当前遇到个问题,gorm 中多个字段任意组合查询,需要构造成底层转化为sql 为select id from table where (num,name) in ((num1,'name1'),(num2,'name2')),
问题是gorm
尝试解决1:查询的结果db.Where("tenant_id in (?) or region_id in (?) or status in (?)",",tenantIdList,regionIdList,statusList),
转化为sql为 SELECT count(*) FROM `orders` WHERE ( tenant_id in ('tenant_1','tenant_2','admin') or region_id in ('1,2,4') or status in ('1,4')),查询不到结果
尝试解决2:db.Where("order_name like ? and (tenant_id,region_id,status) in (?,?,?)",
// "%"+query+"%",tenantIdList,regionIdList,statusList). 直接报转化为sql报错
gorm 如何构建 多个字段,任意组合的查询,形如sql where (user_id,type) in ((568,6),(569,6),(600,8))
wanderingpuppy · · 4304 次点击更多评论
老哥, gorm 现在有了
db.Where("(name, age, role) IN ?", [][]interface{}{{"jinzhu", 18, "admin"}, {"jinzhu2", 19, "user"}}).Find(&users)
// SELECT * FROM users WHERE (name, age, role) IN (("jinzhu", 18, "admin"), ("jinzhu 2", 19, "user"));
#3