Documentation ¶
Index ¶
- func New(dialect, dbPsn string, cfg *gorm.Config) (db *gorm.DB, err error)
- func Transaction(db *gorm.DB, fn InTransaction) (err error)
- type DB
- func (cdb *DB) Create(ctx context.Context, db *gorm.DB, input interface{}) error
- func (cdb *DB) CreateInBatches(ctx context.Context, db *gorm.DB, input interface{}, batchSize int) error
- func (cdb *DB) Delete(ctx context.Context, db *gorm.DB, cond ...interface{}) error
- func (cdb *DB) DeletePermanently(ctx context.Context, db *gorm.DB, cond ...interface{}) error
- func (cdb *DB) Exist(ctx context.Context, db *gorm.DB, cond ...interface{}) (bool, error)
- func (cdb *DB) List(ctx context.Context, db *gorm.DB, output interface{}, lq *ListQueryCondition, ...) error
- func (cdb *DB) ParseCond(cond ...interface{}) []interface{}
- func (cdb *DB) Update(ctx context.Context, db *gorm.DB, updates interface{}, cond ...interface{}) error
- func (cdb *DB) View(ctx context.Context, db *gorm.DB, output interface{}, cond ...interface{}) error
- type InTransaction
- type Intf
- type ListQueryCondition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Transaction ¶
func Transaction(db *gorm.DB, fn InTransaction) (err error)
Transaction execute the input func in a transaction
Types ¶
type DB ¶
type DB struct { // Model must be set to a specific model instance. e.g: model.User{} Model interface{} // GDB holds previous DB instance that just executed the query GDB *gorm.DB }
DB represents the client for common usages
func (*DB) CreateInBatches ¶
func (cdb *DB) CreateInBatches(ctx context.Context, db *gorm.DB, input interface{}, batchSize int) error
CreateInBatches creates batch of new record on database.
func (*DB) DeletePermanently ¶ added in v1.0.2
DeletePermanently deletes record matching given conditions permanently.
func (*DB) List ¶
func (cdb *DB) List(ctx context.Context, db *gorm.DB, output interface{}, lq *ListQueryCondition, count *int64) error
List returns list of records retrievable after filter & pagination if given.
func (*DB) ParseCond ¶
func (cdb *DB) ParseCond(cond ...interface{}) []interface{}
ParseCond returns standard [sqlString, vars] format for query, powered by gowhere package (configurable version)
type InTransaction ¶
InTransaction defines the transaction wrapper function
type Intf ¶
type Intf interface { // Create creates a new record on database. // `input` must be a non-nil pointer of the model. e.g: `input := &model.User{}` Create(ctx context.Context, db *gorm.DB, input interface{}) error // View returns single record matching the given conditions. // `output` must be a non-nil pointer of the model. e.g: `output := new(model.User)` // Note: RecordNotFound error is returned when there is no record that matches the conditions View(ctx context.Context, db *gorm.DB, output interface{}, cond ...interface{}) error // List returns list of records retrievable after filter & pagination if given. // `output` must be a non-nil pointer of slice of the model. e.g: `data := []*model.User{}; db.List(dbconn, &data, nil, nil)` // `lq` can be nil, then no filter & pagination are applied // `count` can also be nil, then no extra query is executed to get the total count List(ctx context.Context, db *gorm.DB, output interface{}, lq *ListQueryCondition, count *int64) error // Update updates data of the records matching the given conditions. // `updates` could be a model struct or map[string]interface{} // Note: DB.Model must be provided in order to get the correct model/table Update(ctx context.Context, db *gorm.DB, updates interface{}, cond ...interface{}) error // Delete deletes record matching given conditions. // `cond` can be an instance of the model, then primary key will be used as the condition Delete(ctx context.Context, db *gorm.DB, cond ...interface{}) error // Exist checks whether there is record matching the given conditions. Exist(ctx context.Context, db *gorm.DB, cond ...interface{}) (bool, error) // CreateInBatches creates batch of new record on database. // `input` must be a array non-nil pointer of the model. e.g: `input := []*model.User` CreateInBatches(ctx context.Context, db *gorm.DB, input interface{}, batchSize int) error // ParseCond returns standard [sqlString, vars] format for query, powered by gowhere package (with default config) ParseCond(cond ...interface{}) []interface{} // DeletePermanently deletes record matching given conditions permanently. // `cond` can be an instance of the model, then primary key will be used as the condition DeletePermanently(ctx context.Context, db *gorm.DB, cond ...interface{}) error }
Intf represents the common db interface
Click to show internal directories.
Click to hide internal directories.