条件比较灵活,可以用于 db.Frist, db.Last, db.Find, db.Where 等方法。

单个整数

指定主键id

3

sql: WHERE id = 3

一组整数

指定一组主键id

[]int{1,2,3}

sql: id in (1,2,3)

字符串开头,后跟参数

简单 sql

"age = ?", 11

sql: age = 11

"name = ?", "user1"

sql: name = "user1"

结构

将只查询具有值的那些字段

&User{Name: "user1", Age: 12}

sql: name = "user1" AND age = 12

映射 map[string]interface{}

map[string]{"name": "user1", "age": 12}

sql: name = "user1" AND age = 12

05-08 23:24