创建
创建
(*DB)Create(value interface{}) (tx *DB)
(*DB)Create(value interface{}) (tx *DB)user := User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}
result := db.Create(&user) // 通过数据的指针来创建
user.ID // 返回插入数据的主键
result.Error // 返回 error
result.RowsAffected // 返回插入记录的条数users := []*User{
{Name: "Jinzhu", Age: 18, Birthday: time.Now()},
{Name: "Jackson", Age: 19, Birthday: time.Now()},
}
result := db.Create(users) // pass a slice to insert multiple row
result.Error // returns error
result.RowsAffected // returns inserted records count(*DB)CreateInBatches(value interface{}, batchSize int) (tx *DB)
(*DB)CreateInBatches(value interface{}, batchSize int) (tx *DB)用指定的字段创建记录
Select(query interface{}, args ...interface{}) (tx *DB)
Select(query interface{}, args ...interface{}) (tx *DB)Omit(columns ...string) (tx *DB)
Omit(columns ...string) (tx *DB)创建钩子
根据Map创建
关联创建
默认值
最后更新于