高级查询
1 智能选择字段
type User struct {
ID uint
Name string
Age int
Gender string
// hundreds of fields
}
type APIUser struct {
ID uint
Name string
}
// GORM will automatically select `id`, `name` fields when querying
db.Model(&User{}).Limit(10).Find(&APIUser{})
// SQL: SELECT `id`, `name` FROM `users` LIMIT 102 Locking
2.1.1 Strength- 锁强度控制
Strength- 锁强度控制2.1.2 Options- 锁行为选项
Options- 锁行为选项2.1.3 Table- 锁目标表
Table- 锁目标表3 子查询
3.1 从子查询中查询
4 多列IN
5 FirstOrInit/Attrs/Assign
5.1 FirstOrInit(dest interface{}, conds ...interface{}) (tx *DB)
FirstOrInit(dest interface{}, conds ...interface{}) (tx *DB)5.2 Attrs(attrs ...interface{}) (tx *DB)
Attrs(attrs ...interface{}) (tx *DB)5.3 Assign(attrs ...interface{}) (tx *DB)
Assign(attrs ...interface{}) (tx *DB)5.4 FirstOrCreate
6 优化器/索引提示
7 批量查询
8 Pluck
9 Scopes
10 获取匹配的记录数
最后更新于