Xorm GroupBy 取出的数据异常踩坑
1.连表的场景不映射的场景
这样就可以了
2.in 和 ?不兼容的问题
1.不能这样替换,会直接报错
2.查询数据不全
其实sql查询应该有三条的,但是这样查询出来只有1条,需要注意
[xorm] [info] 2021/12/14 10:05:26.127291 [SQL] SELECT `id`, `order_no`, `purchase_no` FROM `eb_tibao_order_purchase` WHERE (((audit_status = ? AND first_purchase_id = ? AND kill_status = ? AND node_id = ?) OR id IN (?) )) ORDER BY id asc LIMIT 20 [2 0 0 30 102112,102070,102124] - 89.114273ms
连表别名的问题
报错场景
count, err := receiver.engine.Alias("c").Join("INNER", "eb_newtibao_order a", "c.order_id = a.id").
Where(whereSlice[0], params...).Count(maj)
解决办法1
加 as
count, err := receiver.engine.Alias("c").Join("INNER", "eb_newtibao_order as a", "c.order_id = a.id").Where(whereSlice[0], params...).Count(maj)
解决办法2
不要用a 关键字
count, err := receiver.engine.Alias("c").Join("INNER", "eb_newtibao_order o", "c.order_id = o.id").
Where(whereSlice[0], params...).Count(maj)
DeletedAt 问题
自动生成的一般会在 DeletedAt 后面加 DeletedAt
连表场景已经验证
DeletedAt time.Time `json:"deleted_at" xorm:"deleted TIMESTAMP"`
//xorm:"deleted TIMESTAMP" xorm操作会自动再sql后面添加 AND (`c`.`deleted_at`=? OR `c`.`deleted_at` IS NULL)
debug模式 rpc调用报错
个人猜测debug模式rpc请求时间太长,类似于请求超时
替换为正常模式
现在可以了
gorm 关于查询字段大写的时候的问题
go-zero
2022/03/19 19:15:20 empty etcd hosts
zrpc报错
panic: duplicate metrics collector registration attempted