Documentation ¶
Index ¶
- type GORMDB
- func (db *GORMDB) AddError(err error) error
- func (db *GORMDB) Assign(attrs ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) Association(column string) *gorm.Association
- func (db *GORMDB) Attrs(attrs ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) AutoMigrate(dst ...interface{}) error
- func (db *GORMDB) Begin(opts ...*sql.TxOptions) GORMDBIOCInterface
- func (db *GORMDB) Clauses(conds ...clause.Expression) GORMDBIOCInterface
- func (db *GORMDB) Commit() GORMDBIOCInterface
- func (db *GORMDB) Connection(fc func(db *gorm.DB) error) (err error)
- func (db *GORMDB) Count(count *int64) GORMDBIOCInterface
- func (db *GORMDB) Create(value interface{}) GORMDBIOCInterface
- func (db *GORMDB) CreateInBatches(value interface{}, batchSize int) GORMDBIOCInterface
- func (db *GORMDB) DB() (*sql.DB, error)
- func (db *GORMDB) Debug() GORMDBIOCInterface
- func (db *GORMDB) Delete(value interface{}, conds ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) Distinct(args ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) Error() error
- func (db *GORMDB) Exec(sql string, values ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) Find(dest interface{}, conds ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) FindInBatches(dest interface{}, batchSize int, fc func(tx *gorm.DB, batch int) error) GORMDBIOCInterface
- func (db *GORMDB) First(dest interface{}, conds ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) FirstOrCreate(dest interface{}, conds ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) FirstOrInit(dest interface{}, conds ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) Get(key string) (interface{}, bool)
- func (db *GORMDB) Group(name string) GORMDBIOCInterface
- func (db *GORMDB) Having(query interface{}, args ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) InstanceGet(key string) (interface{}, bool)
- func (db *GORMDB) InstanceSet(key string, value interface{}) GORMDBIOCInterface
- func (db *GORMDB) Joins(query string, args ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) Last(dest interface{}, conds ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) Limit(limit int) GORMDBIOCInterface
- func (db *GORMDB) Migrator() gorm.Migrator
- func (db *GORMDB) Model(value interface{}) GORMDBIOCInterface
- func (db *GORMDB) Not(query interface{}, args ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) Offset(offset int) GORMDBIOCInterface
- func (db *GORMDB) Omit(columns ...string) GORMDBIOCInterface
- func (db *GORMDB) Or(query interface{}, args ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) Order(value interface{}) GORMDBIOCInterface
- func (db *GORMDB) Pluck(column string, dest interface{}) GORMDBIOCInterface
- func (db *GORMDB) Preload(query string, args ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) Raw(sql string, values ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) Rollback()
- func (db *GORMDB) RollbackTo(name string) GORMDBIOCInterface
- func (db *GORMDB) Row() *sql.Row
- func (db *GORMDB) Rows() (*sql.Rows, error)
- func (db *GORMDB) Save(value interface{}) GORMDBIOCInterface
- func (db *GORMDB) SavePoint(name string) GORMDBIOCInterface
- func (db *GORMDB) Scan(dest interface{}) GORMDBIOCInterface
- func (db *GORMDB) ScanRows(rows *sql.Rows, dest interface{}) error
- func (db *GORMDB) Scopes(funcs ...func(db *gorm.DB) *gorm.DB) GORMDBIOCInterface
- func (db *GORMDB) Select(query interface{}, args ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) Session(config *gorm.Session) GORMDBIOCInterface
- func (db *GORMDB) Set(key string, value interface{}) GORMDBIOCInterface
- func (db *GORMDB) SetupJoinTable(model interface{}, field string, joinTable interface{}) error
- func (db *GORMDB) Table(name string, args ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) Take(dest interface{}, conds ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) ToSQL(queryFn func(tx *gorm.DB) *gorm.DB) string
- func (db *GORMDB) Transaction(fc func(db *gorm.DB) error, opts ...*sql.TxOptions) (err error)
- func (db *GORMDB) Unscoped() GORMDBIOCInterface
- func (db *GORMDB) Update(column string, value interface{}) GORMDBIOCInterface
- func (db *GORMDB) UpdateColumn(column string, value interface{}) GORMDBIOCInterface
- func (db *GORMDB) UpdateColumns(values interface{}) GORMDBIOCInterface
- func (db *GORMDB) Updates(values interface{}) GORMDBIOCInterface
- func (db *GORMDB) Use(plugin gorm.Plugin) error
- func (db *GORMDB) Where(query interface{}, args ...interface{}) GORMDBIOCInterface
- func (db *GORMDB) WithContext(ctx context.Context) GORMDBIOCInterface
- type GORMDBIOCInterface
- type Param
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GORMDB ¶
type GORMDB struct {
// contains filtered or unexported fields
}
func GetGORMDBSingleton ¶
func (*GORMDB) Assign ¶
func (db *GORMDB) Assign(attrs ...interface{}) GORMDBIOCInterface
func (*GORMDB) Association ¶
func (db *GORMDB) Association(column string) *gorm.Association
func (*GORMDB) Attrs ¶
func (db *GORMDB) Attrs(attrs ...interface{}) GORMDBIOCInterface
func (*GORMDB) AutoMigrate ¶
func (*GORMDB) Begin ¶
func (db *GORMDB) Begin(opts ...*sql.TxOptions) GORMDBIOCInterface
Begin begins a transaction
func (*GORMDB) Clauses ¶
func (db *GORMDB) Clauses(conds ...clause.Expression) GORMDBIOCInterface
Clauses Add clauses
func (*GORMDB) Connection ¶
Connection use a db conn to execute Multiple commands,this conn will put conn pool after it is executed.
func (*GORMDB) Count ¶
func (db *GORMDB) Count(count *int64) GORMDBIOCInterface
func (*GORMDB) Create ¶
func (db *GORMDB) Create(value interface{}) GORMDBIOCInterface
Create insert the value into database
func (*GORMDB) CreateInBatches ¶
func (db *GORMDB) CreateInBatches(value interface{}, batchSize int) GORMDBIOCInterface
CreateInBatches insert the value in batches into database
func (*GORMDB) Delete ¶
func (db *GORMDB) Delete(value interface{}, conds ...interface{}) GORMDBIOCInterface
Delete delete value match given conditions, if the value has primary key, then will including the primary key as condition
func (*GORMDB) Distinct ¶
func (db *GORMDB) Distinct(args ...interface{}) GORMDBIOCInterface
Distinct specify distinct fields that you want querying
func (*GORMDB) Exec ¶
func (db *GORMDB) Exec(sql string, values ...interface{}) GORMDBIOCInterface
Exec execute raw sql
func (*GORMDB) Find ¶
func (db *GORMDB) Find(dest interface{}, conds ...interface{}) GORMDBIOCInterface
Find find records that match given conditions
func (*GORMDB) FindInBatches ¶
func (db *GORMDB) FindInBatches(dest interface{}, batchSize int, fc func(tx *gorm.DB, batch int) error) GORMDBIOCInterface
FindInBatches find records in batches
func (*GORMDB) First ¶
func (db *GORMDB) First(dest interface{}, conds ...interface{}) GORMDBIOCInterface
First find first record that match given conditions, order by primary key
func (*GORMDB) FirstOrCreate ¶
func (db *GORMDB) FirstOrCreate(dest interface{}, conds ...interface{}) GORMDBIOCInterface
FirstOrCreate gets the first matched record or create a new one with given conditions (only works with struct, map conditions)
func (*GORMDB) FirstOrInit ¶
func (db *GORMDB) FirstOrInit(dest interface{}, conds ...interface{}) GORMDBIOCInterface
FirstOrInit gets the first matched record or initialize a new instance with given conditions (only works with struct or map conditions)
func (*GORMDB) Group ¶
func (db *GORMDB) Group(name string) GORMDBIOCInterface
Group specify the group method on the find
func (*GORMDB) Having ¶
func (db *GORMDB) Having(query interface{}, args ...interface{}) GORMDBIOCInterface
Having specify HAVING conditions for GROUP BY
func (*GORMDB) InstanceGet ¶
InstanceGet get value with key from current db instance's context
func (*GORMDB) InstanceSet ¶
func (db *GORMDB) InstanceSet(key string, value interface{}) GORMDBIOCInterface
InstanceSet store value with key into current db instance's context
func (*GORMDB) Joins ¶
func (db *GORMDB) Joins(query string, args ...interface{}) GORMDBIOCInterface
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) db.Joins("Account", DB.Select("id").Where("user_id = users.id AND name = ?", "someName").Model(&Account{}))
func (*GORMDB) Last ¶
func (db *GORMDB) Last(dest interface{}, conds ...interface{}) GORMDBIOCInterface
Last find last record that match given conditions, order by primary key
func (*GORMDB) Limit ¶
func (db *GORMDB) Limit(limit int) GORMDBIOCInterface
Limit specify the number of records to be retrieved
func (*GORMDB) Model ¶
func (db *GORMDB) Model(value interface{}) GORMDBIOCInterface
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 (*GORMDB) Not ¶
func (db *GORMDB) Not(query interface{}, args ...interface{}) GORMDBIOCInterface
Not add NOT conditions
func (*GORMDB) Offset ¶
func (db *GORMDB) Offset(offset int) GORMDBIOCInterface
Offset specify the number of records to skip before starting to return the records
func (*GORMDB) Omit ¶
func (db *GORMDB) Omit(columns ...string) GORMDBIOCInterface
Omit specify fields that you want to ignore when creating, updating and querying
func (*GORMDB) Or ¶
func (db *GORMDB) Or(query interface{}, args ...interface{}) GORMDBIOCInterface
Or add OR conditions
func (*GORMDB) Order ¶
func (db *GORMDB) Order(value interface{}) GORMDBIOCInterface
Order specify order when retrieve records from database
db.Order("name DESC") db.Order(clause.OrderByColumn{Column: clause.Column{Name: "name"}, Desc: true})
func (*GORMDB) Pluck ¶
func (db *GORMDB) Pluck(column string, dest interface{}) GORMDBIOCInterface
Pluck used to query single column from a model as a map
var ages []int64 db.Model(&users).Pluck("age", &ages)
func (*GORMDB) Preload ¶
func (db *GORMDB) Preload(query string, args ...interface{}) GORMDBIOCInterface
Preload preload associations with given conditions
db.Preload("Orders", "state NOT IN (?)", "cancelled").Find(&users)
func (*GORMDB) Raw ¶
func (db *GORMDB) Raw(sql string, values ...interface{}) GORMDBIOCInterface
func (*GORMDB) RollbackTo ¶
func (db *GORMDB) RollbackTo(name string) GORMDBIOCInterface
func (*GORMDB) Save ¶
func (db *GORMDB) Save(value interface{}) GORMDBIOCInterface
Save update value in database, if the value doesn't have primary key, will insert it
func (*GORMDB) SavePoint ¶
func (db *GORMDB) SavePoint(name string) GORMDBIOCInterface
func (*GORMDB) Scan ¶
func (db *GORMDB) Scan(dest interface{}) GORMDBIOCInterface
Scan scan value to a struct
func (*GORMDB) 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 (*GORMDB) Select ¶
func (db *GORMDB) Select(query interface{}, args ...interface{}) GORMDBIOCInterface
Select specify fields that you want when querying, creating, updating
func (*GORMDB) Session ¶
func (db *GORMDB) Session(config *gorm.Session) GORMDBIOCInterface
Session create new db session
func (*GORMDB) Set ¶
func (db *GORMDB) Set(key string, value interface{}) GORMDBIOCInterface
Set store value with key into current db instance's context
func (*GORMDB) SetupJoinTable ¶
SetupJoinTable setup join table schema
func (*GORMDB) Table ¶
func (db *GORMDB) Table(name string, args ...interface{}) GORMDBIOCInterface
Table specify the table you would like to run db operations
func (*GORMDB) Take ¶
func (db *GORMDB) Take(dest interface{}, conds ...interface{}) GORMDBIOCInterface
Take return a record that match given conditions, the order will depend on the database implementation
func (*GORMDB) Transaction ¶
Transaction start a transaction as a block, return error will rollback, otherwise to commit.
func (*GORMDB) Unscoped ¶
func (db *GORMDB) Unscoped() GORMDBIOCInterface
func (*GORMDB) Update ¶
func (db *GORMDB) Update(column string, value interface{}) GORMDBIOCInterface
Update update attributes with callbacks, refer: https://gorm.io/docs/update.html#Update-Changed-Fields
func (*GORMDB) UpdateColumn ¶
func (db *GORMDB) UpdateColumn(column string, value interface{}) GORMDBIOCInterface
func (*GORMDB) UpdateColumns ¶
func (db *GORMDB) UpdateColumns(values interface{}) GORMDBIOCInterface
func (*GORMDB) Updates ¶
func (db *GORMDB) Updates(values interface{}) GORMDBIOCInterface
Updates update attributes with callbacks, refer: https://gorm.io/docs/update.html#Update-Changed-Fields
func (*GORMDB) Where ¶
func (db *GORMDB) Where(query interface{}, args ...interface{}) GORMDBIOCInterface
Where add conditions
func (*GORMDB) WithContext ¶
func (db *GORMDB) WithContext(ctx context.Context) GORMDBIOCInterface
WithContext change current instance db's context to ctx
type GORMDBIOCInterface ¶
type GORMDBIOCInterface interface { Session(config *gorm_iogormx.Session) GORMDBIOCInterface WithContext(ctx contextx.Context) GORMDBIOCInterface Debug() GORMDBIOCInterface Set(key string, value interface{}) GORMDBIOCInterface Get(key string) (interface{}, bool) InstanceSet(key string, value interface{}) GORMDBIOCInterface InstanceGet(key string) (interface{}, bool) AddError(err error) error DB() (*sql.DB, error) SetupJoinTable(model interface{}, field string, joinTable interface{}) error Use(plugin gorm_iogormx.Plugin) error ToSQL(queryFn func(tx *gorm_iogormx.DB) *gorm_iogormx.DB) string Model(value interface{}) GORMDBIOCInterface Clauses(conds ...clause.Expression) GORMDBIOCInterface Table(name string, args ...interface{}) GORMDBIOCInterface Distinct(args ...interface{}) GORMDBIOCInterface Select(query interface{}, args ...interface{}) GORMDBIOCInterface Omit(columns ...string) GORMDBIOCInterface Where(query interface{}, args ...interface{}) GORMDBIOCInterface Not(query interface{}, args ...interface{}) GORMDBIOCInterface Or(query interface{}, args ...interface{}) GORMDBIOCInterface Joins(query string, args ...interface{}) GORMDBIOCInterface Group(name string) GORMDBIOCInterface Having(query interface{}, args ...interface{}) GORMDBIOCInterface Order(value interface{}) GORMDBIOCInterface Limit(limit int) GORMDBIOCInterface Offset(offset int) GORMDBIOCInterface Scopes(funcs ...func(db *gorm_iogormx.DB) *gorm_iogormx.DB) GORMDBIOCInterface Preload(query string, args ...interface{}) GORMDBIOCInterface Attrs(attrs ...interface{}) GORMDBIOCInterface Assign(attrs ...interface{}) GORMDBIOCInterface Unscoped() GORMDBIOCInterface Raw(sql string, values ...interface{}) GORMDBIOCInterface Error() error Create(value interface{}) GORMDBIOCInterface CreateInBatches(value interface{}, batchSize int) GORMDBIOCInterface Save(value interface{}) GORMDBIOCInterface First(dest interface{}, conds ...interface{}) GORMDBIOCInterface Take(dest interface{}, conds ...interface{}) GORMDBIOCInterface Last(dest interface{}, conds ...interface{}) GORMDBIOCInterface Find(dest interface{}, conds ...interface{}) GORMDBIOCInterface FindInBatches(dest interface{}, batchSize int, fc func(tx *gorm_iogormx.DB, batch int) error) GORMDBIOCInterface FirstOrInit(dest interface{}, conds ...interface{}) GORMDBIOCInterface FirstOrCreate(dest interface{}, conds ...interface{}) GORMDBIOCInterface Update(column string, value interface{}) GORMDBIOCInterface Updates(values interface{}) GORMDBIOCInterface UpdateColumn(column string, value interface{}) GORMDBIOCInterface UpdateColumns(values interface{}) GORMDBIOCInterface Delete(value interface{}, conds ...interface{}) GORMDBIOCInterface Count(count *int64) GORMDBIOCInterface Row() *sql.Row Rows() (*sql.Rows, error) Scan(dest interface{}) GORMDBIOCInterface Pluck(column string, dest interface{}) GORMDBIOCInterface ScanRows(rows *sql.Rows, dest interface{}) error Connection(fc func(db *gorm_iogormx.DB) error) (err error) Transaction(fc func(db *gorm_iogormx.DB) error, opts ...*sql.TxOptions) (err error) Begin(opts ...*sql.TxOptions) GORMDBIOCInterface Commit() GORMDBIOCInterface Rollback() SavePoint(name string) GORMDBIOCInterface RollbackTo(name string) GORMDBIOCInterface Exec(sql string, values ...interface{}) GORMDBIOCInterface Migrator() gorm_iogormx.Migrator AutoMigrate(dst ...interface{}) error Association(column string) *gorm_iogormx.Association }
func GetGORMDBIOCInterface ¶
func GetGORMDBIOCInterface(p *Param) (GORMDBIOCInterface, error)
func GetGORMDBIOCInterfaceSingleton ¶
func GetGORMDBIOCInterfaceSingleton(p *Param) (GORMDBIOCInterface, error)