
切片如何转数组? gorm 的 in 查询不支持切片
1 codehz 2019-09-25 16:33:39 +08:00 首先必须长度固定,然后 var target[5]int copy(target[:], source) |
3 codehz 2019-09-25 16:44:31 +08:00 那就 target := make([]int, n) copy(target[:], source) |
4 chotow 2019-09-25 16:50:39 +08:00 gorm 的 in 查询是支持切片的: http://gorm.io/docs/query.html#Plain-SQL xorm 不支持(吐血) |
5 kedadiannao220 2019-09-25 17:22:31 +08:00 |
6 252748371 OP |
7 252748371 OP 解决了 原来不能传指针! |
8 chotow 2019-09-27 16:39:08 +08:00 @kedadiannao220 #5 xorm Raw SQL 查询的时候,怎么实现 in 传值呢? 我试了下:db.SQL("select * from test").In("id", []uint64{1, 2, 3}).Find(&ret) 这样子并不可以 |
9 kedadiannao220 2019-11-15 17:24:12 +08:00 @chotow 使用 raw sql,就不用再使用 In、where 这些函数了; db.SQL("select * from test where id in xxxx"),这样会存在 sql 注入的风险 |