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