leafGorm

package module
v0.0.0-...-0829b1e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2022 License: MIT Imports: 24 Imported by: 2

Documentation

Index

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) AddError

func (i *Impl) AddError(err error) error

AddError add error to db

func (*Impl) AllowGlobalUpdate

func (i *Impl) AllowGlobalUpdate() bool

AllowGlobalUpdate allow global update

func (*Impl) Assign

func (i *Impl) Assign(attrs ...interface{}) leafSql.ORM

func (*Impl) Association

func (i *Impl) Association(column string) *gorm.Association

func (*Impl) Attrs

func (i *Impl) Attrs(attrs ...interface{}) leafSql.ORM

func (*Impl) AutoMigrate

func (i *Impl) AutoMigrate(dst ...interface{}) error

func (*Impl) Begin

func (i *Impl) Begin(ctx context.Context, opts ...*sql.TxOptions) leafSql.ORM

Begin begins a transaction

func (*Impl) BulkInsert

func (i *Impl) BulkInsert(ctx context.Context, batches int, data ...leafSql.SqlQueryable) error

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) Commit

func (i *Impl) Commit(ctx context.Context) leafSql.ORM

Commit commit a transaction

func (*Impl) ConnPool

func (i *Impl) ConnPool() gorm.ConnPool

ConnPool db conn pool

func (*Impl) Count

func (i *Impl) Count(ctx context.Context, count *int64) leafSql.ORM

func (*Impl) Create

func (i *Impl) Create(ctx context.Context, value interface{}) leafSql.ORM

Create insert the value into database

func (*Impl) DB

func (i *Impl) DB() (*sql.DB, error)

DB returns `*sql.DB`

func (*Impl) Debug

func (i *Impl) Debug() leafSql.ORM

Debug start debug mode

func (*Impl) Delete

func (i *Impl) Delete(ctx context.Context, value interface{}, conds ...interface{}) leafSql.ORM

Delete delete value match given conditions, if the value has primary key, then will including the primary key as condition

func (*Impl) Dialector

func (i *Impl) Dialector() gorm.Dialector

func (*Impl) DisableAutomaticPing

func (i *Impl) DisableAutomaticPing() bool

DisableAutomaticPing

func (*Impl) DisableForeignKeyConstraintWhenMigrating

func (i *Impl) DisableForeignKeyConstraintWhenMigrating() bool

DisableForeignKeyConstraintWhenMigrating

func (*Impl) Distinct

func (i *Impl) Distinct(args ...interface{}) leafSql.ORM

Distinct specify distinct fields that you want querying

func (*Impl) DryRun

func (i *Impl) DryRun() bool

DryRun generate sql without execute

func (*Impl) Error

func (i *Impl) Error() error

func (*Impl) Exec

func (i *Impl) Exec(ctx context.Context, sql string, values ...interface{}) leafSql.ORM

Exec execute raw sql

func (*Impl) Find

func (i *Impl) Find(ctx context.Context, dest interface{}, conds ...interface{}) leafSql.ORM

Find find records that match given conditions

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) First

func (i *Impl) First(ctx context.Context, dest interface{}, conds ...interface{}) leafSql.ORM

First find first record that match given conditions, order by primary key

func (*Impl) FirstOrCreate

func (i *Impl) FirstOrCreate(ctx context.Context, dest interface{}, conds ...interface{}) leafSql.ORM

func (*Impl) FirstOrInit

func (i *Impl) FirstOrInit(ctx context.Context, dest interface{}, conds ...interface{}) leafSql.ORM

func (*Impl) FullSaveAssociations

func (i *Impl) FullSaveAssociations() bool

FullSaveAssociations full save associations

func (*Impl) Get

func (i *Impl) Get(key string) (interface{}, bool)

Get get value with key from current db instance's context

func (*Impl) Gorm

func (i *Impl) Gorm() *gorm.DB

func (*Impl) Group

func (i *Impl) Group(name string) leafSql.ORM

Group specify the group method on the find

func (*Impl) Having

func (i *Impl) Having(query interface{}, args ...interface{}) leafSql.ORM

Having specify HAVING conditions for GROUP BY

func (*Impl) InstanceGet

func (i *Impl) InstanceGet(key string) (interface{}, bool)

InstanceGet get value with key from current db instance's context

func (*Impl) InstanceSet

func (i *Impl) InstanceSet(key string, value interface{}) leafSql.ORM

InstanceSet store value with key into current db instance's context

func (*Impl) Joins

func (i *Impl) Joins(query string, args ...interface{}) leafSql.ORM

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) Last

func (i *Impl) Last(ctx context.Context, dest interface{}, conds ...interface{}) leafSql.ORM

Last find last record that match given conditions, order by primary key

func (*Impl) Limit

func (i *Impl) Limit(limit int) leafSql.ORM

Limit specify the number of records to be retrieved

func (*Impl) Logger

func (i *Impl) Logger() logger.Interface

Logger

func (*Impl) Migrator

func (i *Impl) Migrator() gorm.Migrator

func (*Impl) Model

func (i *Impl) Model(value interface{}) leafSql.ORM

func (*Impl) NamingStrategy

func (i *Impl) NamingStrategy() schema.Namer

NamingStrategy tables, columns naming strategy

func (*Impl) Not

func (i *Impl) Not(query interface{}, args ...interface{}) leafSql.ORM

Not add NOT conditions

func (*Impl) NowFunc

func (i *Impl) NowFunc() func() time.Time

NowFunc the function to be used when creating a new timestamp

func (*Impl) Offset

func (i *Impl) Offset(offset int) leafSql.ORM

Offset specify the number of records to skip before starting to return the records

func (*Impl) Omit

func (i *Impl) Omit(columns ...string) leafSql.ORM

Omit specify fields that you want to ignore when creating, updating and querying

func (*Impl) Or

func (i *Impl) Or(query interface{}, args ...interface{}) leafSql.ORM

Or add OR conditions

func (*Impl) Order

func (i *Impl) Order(value interface{}) leafSql.ORM

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) Ping

func (i *Impl) Ping(ctx context.Context) error

func (*Impl) Pluck

func (i *Impl) Pluck(ctx context.Context, column string, dest interface{}) leafSql.ORM

Pluck used to query single column from a model as a map

var ages []int64
db.Find(&users).Pluck("age", &ages)

func (*Impl) Plugins

func (i *Impl) Plugins() map[string]gorm.Plugin

Plugins registered plugins

func (*Impl) Preload

func (i *Impl) Preload(query string, args ...interface{}) leafSql.ORM

Preload preload associations with given conditions

db.Preload("Orders", "state NOT IN (?)", "cancelled").Find(&users)

func (*Impl) PrepareStmt

func (i *Impl) PrepareStmt() bool

PrepareStmt executes the given query in cached statement

func (*Impl) Raw

func (i *Impl) Raw(sql string, values ...interface{}) leafSql.ORM

func (*Impl) Rollback

func (i *Impl) Rollback(ctx context.Context) leafSql.ORM

Rollback rollback a transaction

func (*Impl) RollbackTo

func (i *Impl) RollbackTo(ctx context.Context, name string) leafSql.ORM

func (*Impl) Row

func (i *Impl) Row(ctx context.Context) *sql.Row

func (*Impl) Rows

func (i *Impl) Rows(ctx context.Context) (*sql.Rows, error)

func (*Impl) RowsAffected

func (i *Impl) RowsAffected() int64

func (*Impl) Save

func (i *Impl) Save(ctx context.Context, value interface{}) leafSql.ORM

Save update value in database, if the value doesn't have primary key, will insert it

func (*Impl) SavePoint

func (i *Impl) SavePoint(ctx context.Context, name string) leafSql.ORM

func (*Impl) Scan

func (i *Impl) Scan(ctx context.Context, dest interface{}) leafSql.ORM

Scan scan value to a struct

func (*Impl) ScanRows

func (i *Impl) ScanRows(ctx context.Context, rows *sql.Rows, dest interface{}) error

func (*Impl) Scopes

func (i *Impl) Scopes(funcs ...func(db leafSql.ORM) leafSql.ORM) leafSql.ORM

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) Select

func (i *Impl) Select(query interface{}, args ...interface{}) leafSql.ORM

Select specify fields that you want when querying, creating, updating

func (*Impl) Session

func (i *Impl) Session(config *gorm.Session) leafSql.ORM

Session create new db session

func (*Impl) Set

func (i *Impl) Set(key string, value interface{}) leafSql.ORM

Set store value with key into current db instance's context

func (*Impl) SetupJoinTable

func (i *Impl) SetupJoinTable(model interface{}, field string, joinTable interface{}) error

func (*Impl) SimplePaginateData

func (i *Impl) SimplePaginateData(ctx context.Context, items interface{}, options leafSql.PaginateOptions) (leafModel.BaseSimplePagingResponse, error)

func (*Impl) SkipDefaultTransaction

func (i *Impl) SkipDefaultTransaction() bool

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) Statement

func (i *Impl) Statement() *gorm.Statement

func (*Impl) Table

func (i *Impl) Table(name string, args ...interface{}) leafSql.ORM

Table specify the table you would like to run db operations

func (*Impl) Take

func (i *Impl) Take(ctx context.Context, dest interface{}, conds ...interface{}) leafSql.ORM

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) Unscoped

func (i *Impl) Unscoped() leafSql.ORM

func (*Impl) Update

func (i *Impl) Update(ctx context.Context, column string, value interface{}) leafSql.ORM

Update update attributes with callbacks, refer: https://gorm.io/docs/update.html#Update-Changed-Fields

func (*Impl) UpdateColumn

func (i *Impl) UpdateColumn(ctx context.Context, column string, value interface{}) leafSql.ORM

func (*Impl) UpdateColumns

func (i *Impl) UpdateColumns(ctx context.Context, values interface{}) leafSql.ORM

func (*Impl) Updates

func (i *Impl) Updates(ctx context.Context, values interface{}) leafSql.ORM

Updates update attributes with callbacks, refer: https://gorm.io/docs/update.html#Update-Changed-Fields

func (*Impl) Use

func (i *Impl) Use(plugin gorm.Plugin) error

func (*Impl) Where

func (i *Impl) Where(query interface{}, args ...interface{}) leafSql.ORM

Where add conditions

func (*Impl) WithContext

func (i *Impl) WithContext(ctx context.Context) leafSql.ORM

WithContext change current instance db's context to ctx

Directories

Path Synopsis
mysql module
plugin
softDelete Module
postgresql module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL