Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When a custom model is used in AppleInterface #1053

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

foxtech6
Copy link

@foxtech6 foxtech6 commented Dec 29, 2023

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Adds a prefix to tables when using a custom model in ApplyInterface

User Case Description

type Querier interface {
	// SELECT * FROM @@table WHERE uuid = @uuid
	FilterWithUUID(uuid string) ([]gen.T, error)
}

//....

g.ApplyInterface(func(Querier){}, custom.User{})

RESULT:
Method FilterWithUUID in users.gen.go before:

func (u userDo) u(uuid string) (result []custom.User, err error) {
	var params []interface{}

	var generateSQL strings.Builder
	params = append(params, uuid)
	generateSQL.WriteString("SELECT * FROM users WHERE uuid = ? ")

	var executeSQL *gorm.DB
	executeSQL = u.UnderlyingDB().Raw(generateSQL.String(), params...).Find(&result) // ignore_security_alert
	err = executeSQL.Error

	return
}

and after fix:

func (u userDo) u(uuid string) (result []custom.User, err error) {
	var params []interface{}

	var generateSQL strings.Builder
	params = append(params, uuid)
	generateSQL.WriteString("SELECT * FROM table_prefix.users WHERE uuid = ? ")

	var executeSQL *gorm.DB
	executeSQL = u.UnderlyingDB().Raw(generateSQL.String(), params...).Find(&result) // ignore_security_alert
	err = executeSQL.Error

	return
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant