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

gorm 支持golden db #7082

Open
codemonk-sunhui opened this issue Jun 25, 2024 · 0 comments
Open

gorm 支持golden db #7082

codemonk-sunhui opened this issue Jun 25, 2024 · 0 comments
Assignees
Labels
type:feature_request feature request

Comments

@codemonk-sunhui
Copy link

codemonk-sunhui commented Jun 25, 2024

Describe the feature

golden db 的查询兼容mysql, 是没有问题的,
但是goldendb对于不同的查询方式,返回的column有的是大写,有的是小写
导致不论struct里面column配置大写还是小写,都有一部分scan不到数据。
tx.Table(Table).Find(&hostApps) 返回大写
tx.Table(Table).Find(&hostApps).Where("xxx=?","xxx") 返回小写

我的想法是修改LookUpField的实现,兼容这种问题。

func (schema Schema) LookUpField(name string) *Field {
	if field, ok := schema.FieldsByDBName[name]; ok {
		return field
	}
	if field, ok := schema.FieldsByName[name]; ok {
		return field
	}
	if field, ok := schema.FieldsByDBName[strings.ToLower(name)]; ok {
		return field
	}
	if field, ok := schema.FieldsByName[strings.ToLower(name)]; ok {
		return field
	}
	if field, ok := schema.FieldsByDBName[strings.ToUpper(name)]; ok {
		return field
	}
	if field, ok := schema.FieldsByName[strings.ToUpper(name)]; ok {
		return field
	}
	return nil
}

不知道有没有其他更好的解决方法。比如plugin的方式能重写这部分吗?
有的话,希望告知。

Motivation

Related Issues

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

No branches or pull requests

2 participants