Documentation ¶
Index ¶
- type Impl
- func (i *Impl) AddError(err error) error
- func (i *Impl) AllowGlobalUpdate() bool
- func (i *Impl) Assign(attrs ...interface{}) leafSql.ORM
- func (i *Impl) Association(column string) *gorm.Association
- func (i *Impl) Attrs(attrs ...interface{}) leafSql.ORM
- func (i *Impl) AutoMigrate(dst ...interface{}) error
- func (i *Impl) Begin(ctx context.Context, opts ...*sql.TxOptions) leafSql.ORM
- func (i *Impl) BulkInsert(ctx context.Context, batches int, data ...leafSql.SqlQueryable) error
- func (i *Impl) ClauseBuilders() map[string]clause.ClauseBuilder
- func (i *Impl) Clauses(conds ...clause.Expression) leafSql.ORM
- func (i *Impl) Commit(ctx context.Context) leafSql.ORM
- func (i *Impl) ConnPool() gorm.ConnPool
- func (i *Impl) Count(ctx context.Context, count *int64) leafSql.ORM
- func (i *Impl) Create(ctx context.Context, value interface{}) leafSql.ORM
- func (i *Impl) DB() (*sql.DB, error)
- func (i *Impl) Debug() leafSql.ORM
- func (i *Impl) Delete(ctx context.Context, value interface{}, conds ...interface{}) leafSql.ORM
- func (i *Impl) Dialector() gorm.Dialector
- func (i *Impl) DisableAutomaticPing() bool
- func (i *Impl) DisableForeignKeyConstraintWhenMigrating() bool
- func (i *Impl) Distinct(args ...interface{}) leafSql.ORM
- func (i *Impl) DryRun() bool
- func (i *Impl) Error() error
- func (i *Impl) Exec(ctx context.Context, sql string, values ...interface{}) leafSql.ORM
- func (i *Impl) Find(ctx context.Context, dest interface{}, conds ...interface{}) leafSql.ORM
- func (i *Impl) FindInBatches(ctx context.Context, dest interface{}, batchSize int, ...) leafSql.ORM
- func (i *Impl) First(ctx context.Context, dest interface{}, conds ...interface{}) leafSql.ORM
- func (i *Impl) FirstOrCreate(ctx context.Context, dest interface{}, conds ...interface{}) leafSql.ORM
- func (i *Impl) FirstOrInit(ctx context.Context, dest interface{}, conds ...interface{}) leafSql.ORM
- func (i *Impl) FullSaveAssociations() bool
- func (i *Impl) Get(key string) (interface{}, bool)
- func (i *Impl) Gorm() *gorm.DB
- func (i *Impl) Group(name string) leafSql.ORM
- func (i *Impl) Having(query interface{}, args ...interface{}) leafSql.ORM
- func (i *Impl) InstanceGet(key string) (interface{}, bool)
- func (i *Impl) InstanceSet(key string, value interface{}) leafSql.ORM
- func (i *Impl) Joins(query string, args ...interface{}) leafSql.ORM
- func (i *Impl) Last(ctx context.Context, dest interface{}, conds ...interface{}) leafSql.ORM
- func (i *Impl) Limit(limit int) leafSql.ORM
- func (i *Impl) Logger() logger.Interface
- func (i *Impl) Migrator() gorm.Migrator
- func (i *Impl) Model(value interface{}) leafSql.ORM
- func (i *Impl) NamingStrategy() schema.Namer
- func (i *Impl) Not(query interface{}, args ...interface{}) leafSql.ORM
- func (i *Impl) NowFunc() func() time.Time
- func (i *Impl) Offset(offset int) leafSql.ORM
- func (i *Impl) Omit(columns ...string) leafSql.ORM
- func (i *Impl) Or(query interface{}, args ...interface{}) leafSql.ORM
- func (i *Impl) Order(value interface{}) leafSql.ORM
- func (i *Impl) PaginateData(ctx context.Context, items interface{}, options leafSql.PaginateOptions) (leafModel.BasePagingResponse, error)
- func (i *Impl) Ping(ctx context.Context) error
- func (i *Impl) Pluck(ctx context.Context, column string, dest interface{}) leafSql.ORM
- func (i *Impl) Plugins() map[string]gorm.Plugin
- func (i *Impl) Preload(query string, args ...interface{}) leafSql.ORM
- func (i *Impl) PrepareStmt() bool
- func (i *Impl) Raw(sql string, values ...interface{}) leafSql.ORM
- func (i *Impl) Rollback(ctx context.Context) leafSql.ORM
- func (i *Impl) RollbackTo(ctx context.Context, name string) leafSql.ORM
- func (i *Impl) Row(ctx context.Context) *sql.Row
- func (i *Impl) Rows(ctx context.Context) (*sql.Rows, error)
- func (i *Impl) RowsAffected() int64
- func (i *Impl) Save(ctx context.Context, value interface{}) leafSql.ORM
- func (i *Impl) SavePoint(ctx context.Context, name string) leafSql.ORM
- func (i *Impl) Scan(ctx context.Context, dest interface{}) leafSql.ORM
- func (i *Impl) ScanRows(ctx context.Context, rows *sql.Rows, dest interface{}) error
- func (i *Impl) Scopes(funcs ...func(db leafSql.ORM) leafSql.ORM) leafSql.ORM
- func (i *Impl) Select(query interface{}, args ...interface{}) leafSql.ORM
- func (i *Impl) Session(config *gorm.Session) leafSql.ORM
- func (i *Impl) Set(key string, value interface{}) leafSql.ORM
- func (i *Impl) SetupJoinTable(model interface{}, field string, joinTable interface{}) error
- func (i *Impl) SimplePaginateData(ctx context.Context, items interface{}, options leafSql.PaginateOptions) (leafModel.BaseSimplePagingResponse, error)
- func (i *Impl) SkipDefaultTransaction() bool
- func (i *Impl) Statement() *gorm.Statement
- func (i *Impl) Table(name string, args ...interface{}) leafSql.ORM
- func (i *Impl) Take(ctx context.Context, dest interface{}, conds ...interface{}) leafSql.ORM
- func (i *Impl) Transaction(ctx context.Context, fc func(leafSql.ORM) error, opts ...*sql.TxOptions) error
- func (i *Impl) Unscoped() leafSql.ORM
- func (i *Impl) Update(ctx context.Context, column string, value interface{}) leafSql.ORM
- func (i *Impl) UpdateColumn(ctx context.Context, column string, value interface{}) leafSql.ORM
- func (i *Impl) UpdateColumns(ctx context.Context, values interface{}) leafSql.ORM
- func (i *Impl) Updates(ctx context.Context, values interface{}) leafSql.ORM
- func (i *Impl) Use(plugin gorm.Plugin) error
- func (i *Impl) Where(query interface{}, args ...interface{}) leafSql.ORM
- func (i *Impl) WithContext(ctx context.Context) leafSql.ORM
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Impl ¶
type Impl struct { GormDB *gorm.DB GormDBDryRun *gorm.DB Log leafLogger.Logger DatabaseName string DataStoreProduct newrelic.DatastoreProduct }
func (*Impl) AllowGlobalUpdate ¶
AllowGlobalUpdate allow global update
func (*Impl) Association ¶
func (i *Impl) Association(column string) *gorm.Association
func (*Impl) AutoMigrate ¶
func (*Impl) BulkInsert ¶
func (*Impl) ClauseBuilders ¶
func (i *Impl) ClauseBuilders() map[string]clause.ClauseBuilder
ClauseBuilders clause builder
func (*Impl) Clauses ¶
func (i *Impl) Clauses(conds ...clause.Expression) leafSql.ORM
Clauses Add clauses
func (*Impl) Delete ¶
Delete delete value match given conditions, if the value has primary key, then will including the primary key as condition
func (*Impl) DisableForeignKeyConstraintWhenMigrating ¶
DisableForeignKeyConstraintWhenMigrating
func (*Impl) FindInBatches ¶
func (i *Impl) FindInBatches(ctx context.Context, dest interface{}, batchSize int, fc func(tx leafSql.ORM, batch int) error) leafSql.ORM
FindInBatches find records in batches
func (*Impl) FirstOrCreate ¶
func (*Impl) FirstOrInit ¶
func (*Impl) FullSaveAssociations ¶
FullSaveAssociations full save associations
func (*Impl) InstanceGet ¶
InstanceGet get value with key from current db instance's context
func (*Impl) InstanceSet ¶
InstanceSet store value with key into current db instance's context
func (*Impl) 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 (*Impl) NamingStrategy ¶
NamingStrategy tables, columns naming strategy
func (*Impl) Offset ¶
Offset specify the number of records to skip before starting to return the records
func (*Impl) Omit ¶
Omit specify fields that you want to ignore when creating, updating and querying
func (*Impl) 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 (*Impl) PaginateData ¶
func (i *Impl) PaginateData(ctx context.Context, items interface{}, options leafSql.PaginateOptions) (leafModel.BasePagingResponse, error)
func (*Impl) Pluck ¶
Pluck used to query single column from a model as a map
var ages []int64 db.Find(&users).Pluck("age", &ages)
func (*Impl) Preload ¶
Preload preload associations with given conditions
db.Preload("Orders", "state NOT IN (?)", "cancelled").Find(&users)
func (*Impl) PrepareStmt ¶
PrepareStmt executes the given query in cached statement
func (*Impl) RowsAffected ¶
func (*Impl) Save ¶
Save update value in database, if the value doesn't have primary key, will insert it
func (*Impl) 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 (*Impl) SetupJoinTable ¶
func (*Impl) SimplePaginateData ¶
func (i *Impl) SimplePaginateData(ctx context.Context, items interface{}, options leafSql.PaginateOptions) (leafModel.BaseSimplePagingResponse, error)
func (*Impl) SkipDefaultTransaction ¶
GORM perform single create, update, delete operations in transactions by default to ensure database data integrity You can disable it by setting `SkipDefaultTransaction` to true
func (*Impl) Take ¶
Take return a record that match given conditions, the order will depend on the database implementation
func (*Impl) Transaction ¶
func (i *Impl) Transaction(ctx context.Context, fc func(leafSql.ORM) error, opts ...*sql.TxOptions) error
Transaction start a transaction as a block, return error will rollback, otherwise to commit.
func (*Impl) Update ¶
Update update attributes with callbacks, refer: https://gorm.io/docs/update.html#Update-Changed-Fields
func (*Impl) UpdateColumn ¶
func (*Impl) UpdateColumns ¶
func (*Impl) Updates ¶
Updates update attributes with callbacks, refer: https://gorm.io/docs/update.html#Update-Changed-Fields