open-falcon-backend: github.com/Cepave/open-falcon-backend/common/gorm Index | Files

package gorm

import "github.com/Cepave/open-falcon-backend/common/gorm"

Index

Package Files

env.go gorm_wrapper.go

type ErrorConverter Uses

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 Uses

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

Raise panic if the error is not nil

func (ErrorConverter) PanicIfError Uses

func (self ErrorConverter) PanicIfError(err error)

Raise panic if the error is not nil

type GormDbExt Uses

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

func ToDefaultGormDbExt Uses

func ToDefaultGormDbExt(gormDb *gorm.DB) *GormDbExt

Converts gormDb to GormDbExt with conversion of DbError

func ToGormDbExt Uses

func ToGormDbExt(gormDb *gorm.DB) *GormDbExt

Converts gorm.DB to GormDbExt

func (*GormDbExt) IfRecordNotFound Uses

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 Uses

func (self *GormDbExt) InTx(txCallback TxCallback)

Executes gorm in transaction

func (*GormDbExt) IsRecordNotFound Uses

func (self *GormDbExt) IsRecordNotFound() bool

func (*GormDbExt) IterateRows Uses

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

Iterate rows(and close it) with callback

func (*GormDbExt) PanicIfError Uses

func (self *GormDbExt) PanicIfError() *GormDbExt

Raise panic if the Gorm has error

func (*GormDbExt) Rows Uses

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

Same as Rows() with panic instead of returned error

func (*GormDbExt) ScanRows Uses

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

Same as ScanRows with panic instead of returned error

func (*GormDbExt) SelectWithFoundRows Uses

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 Uses

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

Callback function for transaction

type TxCallbackFunc Uses

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

the function object delegates the TxCallback interface

func (TxCallbackFunc) InTx Uses

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

Package gorm imports 6 packages (graph) and is imported by 7 packages. Updated 2017-07-14. Refresh now. Tools for package owners.