Documentation ¶
Index ¶
- type ChainAblePool
- type ConnPool
- type Db
- func (db *Db) Assign(attrs ...interface{}) (tx *Db)
- func (db *Db) Attrs(attrs ...interface{}) (tx *Db)
- func (db *Db) Begin(opts ...*sql.TxOptions) (tx *Db)
- func (db *Db) Clauses(conds ...clause.Expression) (tx *Db)
- func (db *Db) Commit() (tx *Db)
- func (db *Db) Count(count *int64) (tx *Db)
- func (db *Db) Create(value interface{}) (tx *Db)
- func (db *Db) CreateInBatches(value interface{}, batchSize int) (tx *Db)
- func (db *Db) Delete(value interface{}, conds ...interface{}) (tx *Db)
- func (db *Db) Distinct(args ...interface{}) (tx *Db)
- func (db *Db) Exec(sql string, values ...interface{}) (tx *Db)
- func (db *Db) Find(dest interface{}, conds ...interface{}) (tx *Db)
- func (db *Db) FindInBatches(dest interface{}, batchSize int, fc func(tx *Db, batch int) error) *Db
- func (db *Db) First(dest interface{}, conds ...interface{}) (tx *Db)
- func (db *Db) FirstOrCreate(dest interface{}, conds ...interface{}) (tx *Db)
- func (db *Db) FirstOrInit(dest interface{}, conds ...interface{}) (tx *Db)
- func (db *Db) Group(name string) (tx *Db)
- func (db *Db) Having(query interface{}, args ...interface{}) (tx *Db)
- func (db *Db) Joins(query string, args ...interface{}) (tx *Db)
- func (db *Db) Last(dest interface{}, conds ...interface{}) (tx *Db)
- func (db *Db) Limit(limit int) (tx *Db)
- func (db *Db) Model(value interface{}) (tx *Db)
- func (db *Db) Not(query interface{}, args ...interface{}) (tx *Db)
- func (db *Db) Offset(offset int) (tx *Db)
- func (db *Db) Omit(columns ...string) (tx *Db)
- func (db *Db) Or(query interface{}, args ...interface{}) (tx *Db)
- func (db *Db) Order(value interface{}) (tx *Db)
- func (db *Db) Pluck(column string, dest interface{}) (tx *Db)
- func (db *Db) Preload(query string, args ...interface{}) (tx *Db)
- func (db *Db) Raw(sql string, values ...interface{}) (tx *Db)
- func (db *Db) Rollback() (tx *Db)
- func (db *Db) RollbackTo(name string) (tx *Db)
- func (db *Db) Row() *sql.Row
- func (db *Db) Rows() (*sql.Rows, error)
- func (db *Db) RunFinisher()
- func (db *Db) Save(value interface{}) (tx *Db)
- func (db *Db) SavePoint(name string) (tx *Db)
- func (db *Db) Scan(dest interface{}) (tx *Db)
- func (db *Db) ScanRows(rows *sql.Rows, dest interface{}) error
- func (db *Db) Scopes(funcs ...func(*Db) *Db) (tx *Db)
- func (db *Db) Select(query interface{}, args ...interface{}) (tx *Db)
- func (db *Db) Table(name string, args ...interface{}) (tx *Db)
- func (db *Db) Take(dest interface{}, conds ...interface{}) (tx *Db)
- func (db *Db) Transaction(fc func(tx *Db) error, opts ...*sql.TxOptions) (err error)
- func (db *Db) Unscoped() (tx *Db)
- func (db *Db) Update(column string, value interface{}) (tx *Db)
- func (db *Db) UpdateColumn(column string, value interface{}) (tx *Db)
- func (db *Db) UpdateColumns(values interface{}) (tx *Db)
- func (db *Db) Updates(values interface{}) (tx *Db)
- func (db *Db) Where(query interface{}, args ...interface{}) (tx *Db)
- type FinisherPool
- type Statement
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChainAblePool ¶
type ChainAblePool struct { IsCall bool Params []interface{} }
type Db ¶
type Db struct { *gorm.DB Statement Statement ConnPool ConnPool // contains filtered or unexported fields }
func (*Db) CreateInBatches ¶
CreateInBatches insert the value in batches into database
func (*Db) Delete ¶
Delete delete value match given conditions, if the value has primary key, then will including the primary key as condition
func (*Db) FindInBatches ¶
FindInBatches find records in batches
func (*Db) FirstOrCreate ¶
func (*Db) FirstOrInit ¶
func (*Db) Joins ¶
Joins specify Joins conditions
db.Joins("Account").Find(&user) db.Joins("JOIN emails ON emails.user_id = users.id AND emails.email = ?", "jinzhu@example.org").Find(&user)
func (*Db) Model ¶
Model specify the model you would like to run db operations
// update all users's name to `hello` db.Model(&User{}).Update("name", "hello") // if user's primary key is non-blank, will use it as condition, then will only update the user's name to `hello` db.Model(&user).Update("name", "hello")
func (*Db) Offset ¶
Offset specify the number of records to skip before starting to return the records
func (*Db) Order ¶
Order specify order when retrieve records from database
db.Order("name DESC") db.Order(clause.OrderByColumn{Column: clause.Column{Name: "name"}, Desc: true})
func (*Db) Pluck ¶
Pluck used to query single column from a model as a map
var ages []int64 db.Find(&users).Pluck("age", &ages)
func (*Db) Preload ¶
Preload preload associations with given conditions
db.Preload("Orders", "state NOT IN (?)", "cancelled").Find(&users)
func (*Db) RollbackTo ¶
func (*Db) RunFinisher ¶
func (db *Db) RunFinisher()
func (*Db) Save ¶
Save update value in database, if the value doesn't have primary key, will insert it
func (*Db) Scopes ¶
Scopes pass current database connection to arguments `func(Db) Db`, which could be used to add conditions dynamically
func AmountGreaterThan1000(db *gorm.Db) *gorm.Db { return db.Where("amount > ?", 1000) } func OrderStatus(status []string) func (db *gorm.Db) *gorm.Db { return func (db *gorm.Db) *gorm.Db { return db.Scopes(AmountGreaterThan1000).Where("status in (?)", status) } } db.Scopes(AmountGreaterThan1000, OrderStatus([]string{"paid", "shipped"})).Find(&orders)
func (*Db) Take ¶
Take return a record that match given conditions, the order will depend on the database implementation
func (*Db) Transaction ¶
Transaction start a transaction as a block, return error will rollback, otherwise to commit.
func (*Db) Update ¶
Update update attributes with callbacks, refer: https://gorm.io/docs/update.html#Update-Changed-Fields
func (*Db) UpdateColumn ¶
func (*Db) UpdateColumns ¶
func (*Db) Updates ¶
Updates update attributes with callbacks, refer: https://gorm.io/docs/update.html#Update-Changed-Fields
type FinisherPool ¶
type Statement ¶
type Statement struct { Table ChainAblePool Model ChainAblePool Clauses []ChainAblePool Select []ChainAblePool Distinct []ChainAblePool Omit []ChainAblePool Where []ChainAblePool Not []ChainAblePool Or []ChainAblePool Joins []ChainAblePool Group []ChainAblePool Having []ChainAblePool Order []ChainAblePool Limit ChainAblePool Offset ChainAblePool Scopes []ChainAblePool Preload []ChainAblePool Attrs []ChainAblePool Assign []ChainAblePool Unscoped ChainAblePool Raw []ChainAblePool Create []FinisherPool CreateInBatches []FinisherPool Save []FinisherPool First []FinisherPool Take []FinisherPool Last []FinisherPool Find []FinisherPool FirstOrInit []FinisherPool FirstOrCreate []FinisherPool Update []FinisherPool Updates []FinisherPool UpdateColumn []FinisherPool UpdateColumns []FinisherPool Delete []FinisherPool Count []FinisherPool Row FinisherPool Rows FinisherPool Scan []FinisherPool Pluck []FinisherPool ScanRows FinisherPool Begin []FinisherPool Commit []FinisherPool Rollback []FinisherPool SavePoint []FinisherPool RollbackTo []FinisherPool Exec []FinisherPool }