gorm

package
v3.15.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2018 License: Apache-2.0, Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorConverter

type ErrorConverter func(error) error

Converter of error

var DefaultGormErrorConverter ErrorConverter = func(err error) error {
	if !utils.IsViable(err) {
		return nil
	}

	return db.NewDatabaseError(err)
}

This function converts the error to default database error

See ToGormDbExt

func (ErrorConverter) PanicIfDbError

func (self ErrorConverter) PanicIfDbError(gormDb *gorm.DB)

Raise panic if the error is not nil

func (ErrorConverter) PanicIfError

func (self ErrorConverter) PanicIfError(err error)

Raise panic if the error is not nil

type GormDbExt

type GormDbExt struct {
	// Error converter of Orm
	ConvertError ErrorConverter
	// contains filtered or unexported fields
}

func ToDefaultGormDbExt

func ToDefaultGormDbExt(gormDb *gorm.DB) *GormDbExt

Converts gormDb to GormDbExt with conversion of DbError

func ToGormDbExt

func ToGormDbExt(gormDb *gorm.DB) *GormDbExt

Converts gorm.DB to GormDbExt

func (*GormDbExt) IfRecordNotFound

func (self *GormDbExt) IfRecordNotFound(foundValue interface{}, notFoundValue interface{}) interface{}

Gets the foundValue if there is no error. Or gets notFoundValue if the error is gorm.ErrRecordNotFound

This function also calls PanicIfError(

func (*GormDbExt) InTx

func (self *GormDbExt) InTx(txCallback TxCallback)

Executes gorm in transaction

func (*GormDbExt) IsRecordNotFound

func (self *GormDbExt) IsRecordNotFound() bool

func (*GormDbExt) IterateRows

func (self *GormDbExt) IterateRows(
	rowsCallback db.RowsCallback,
)

Iterate rows(and close it) with callback

func (*GormDbExt) PanicIfError

func (self *GormDbExt) PanicIfError() *GormDbExt

Raise panic if the Gorm has error

func (*GormDbExt) Rows

func (self *GormDbExt) Rows() *sql.Rows

Same as Rows() with panic instead of returned error

func (*GormDbExt) ScanRows

func (self *GormDbExt) ScanRows(rows *sql.Rows, result interface{})

Same as ScanRows with panic instead of returned error

func (*GormDbExt) SelectWithFoundRows

func (self *GormDbExt) SelectWithFoundRows(txCallback TxCallback, paging *commonModel.Paging)

Selects the query by callback and perform "SELECT FOUND_ROWS()" to gets the total number of matched rows

type TxCallback

type TxCallback interface {
	InTx(*gorm.DB) db.TxFinale
}

Callback function for transaction

type TxCallbackFunc

type TxCallbackFunc func(*gorm.DB) db.TxFinale

the function object delegates the TxCallback interface

func (TxCallbackFunc) InTx

func (callbackFunc TxCallbackFunc) InTx(gormDB *gorm.DB) db.TxFinale

Jump to

Keyboard shortcuts

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