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

ShardingKey 不支持 string类型 #180

Open
ankye opened this issue Oct 11, 2024 · 1 comment
Open

ShardingKey 不支持 string类型 #180

ankye opened this issue Oct 11, 2024 · 1 comment
Assignees

Comments

@ankye
Copy link

ankye commented Oct 11, 2024

使用字符串类型的uuid或者openid进入,执行的时候都没有触发分表算法,无法使用分表,
表结构
type O2UID struct {
OID string form:"oid" json:"oid" gorm:"primaryKey;autoIncrement:false;column:oid;type:char(128)"
UID uint64 form:"uid" json:"uid" gorm:"column:uid"
}
查询的时候报错
Unknown column 'o2_uids.oid' in 'where clause'

@ankye
Copy link
Author

ankye commented Oct 11, 2024

问题找到了,但是还是不太理解,在结果接收的结构体赋值,会导致查询语句异常
这个是错误的
o2u := &model.O2UID{OID: oid} <- 这里赋值了
tx := s.conn.GetDB(0).Model(&model.O2UID{}).Where("oid = ?", oid).First(&o2u)
"SELECT * FROM o2_uids_5 WHERE oid = ? AND o2_uids.oid = ? ORDER BY o2_uids_5.oid LIMIT ?"

这个是正确的
o2u := &model.O2UID{}
tx := s.conn.GetDB(0).Model(&model.O2UID{}).Where("oid = ?", oid).First(&o2u)
"SELECT * FROM users_3 WHERE uid = ? ORDER BY users_3.uid LIMIT ?"

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

No branches or pull requests

2 participants