Skip to content

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.

1 participant