gorm 操作

发布时间 2023-05-30 14:31:57作者: bhxuwei

当 where 字典的值为数组时 gorm 会自动转换为条件 IN 查询

where := map[string]interface{}{}
where["id"] = [1,2,3]
where["name"] = "zhangsan"

type userList struct {
    Id int "gorm:'id'"
    Name string "gorm:'name'"
}

Table.Debug().where(where).find(&user).Error
// 生成的sql语句 select * form user where id in (1,2,3)and name = "zhangsan"