Documentation
¶
Overview ¶
Package iorm
Index ¶
- Constants
- Variables
- func GetDB(ctx context.Context, defDB *gorm.DB) *gorm.DB
- func GetDBWithModel(ctx context.Context, defDB *gorm.DB, model interface{}) *gorm.DB
- func InsertSQL(table string, data interface{}) (sql string, binds []interface{})
- func PGInsertSQL(table string, data interface{}) (sql string, binds []interface{})
- func PGUpdateSQL(query string, data interface{}, args ...interface{}) (sql string, binds []interface{})
- func QueryOne(db *gorm.DB, query map[string]interface{}, out interface{}) error
- func QueryPage(db *gorm.DB, pg paginator.Param, out interface{}) (paginator.Infos, error)
- func QueryPageAssociation(db *gorm.DB, pg paginator.Param, out interface{}, column string) (ifo paginator.Infos, err error)
- func QueryPageRelated(db *gorm.DB, pg paginator.Param, out interface{}, foreignKeys ...string) error
- func Update(db *gorm.DB, id uint, attrs ...interface{}) error
- func UpdateAny(db *gorm.DB, query map[string]interface{}, attrs ...interface{}) error
- func UpdateSQL(query string, data interface{}, args ...interface{}) (sql string, binds []interface{})
- type M
Constants ¶
const ( MySQL = "mysql" Postgres = "postgres" )
Variables ¶
var ( ErrZeroOrEmptyValue = errors.New("value must not be zero or empty") ErrObjectAlreadyExist = errors.New("object already exist") ErrHasAssociation = errors.New("object has associate other object") ErrOperateNotPermitted = errors.New("operate not permitted") ErrOutOfRange = errors.New("out of range") ErrInvalidParameter = errors.New("invalid parameter") ErrConflict = errors.New("data field conflict") )
基本错误
Functions ¶
func GetDBWithModel ¶
GetDBWithModel get db with model
func InsertSQL ¶
InsertSQL returns mysql insert sql and binds. param data expects: `struct`, `*struct`, `[]struct`, `[]*struct`, `map[string]interface{}`, `[]map[string]interface{}`.
func PGInsertSQL ¶
PGInsertSQL returns postgres insert sql and binds. param data expects: `struct`, `*struct`, `[]struct`, `[]*struct`, `map[string]interface{}`, `[]map[string]interface{}`.
func PGUpdateSQL ¶
func PGUpdateSQL(query string, data interface{}, args ...interface{}) (sql string, binds []interface{})
PGUpdateSQL returns postgres update sql and binds. param query expects eg: "UPDATE `table` SET $1 WHERE `id` = $2". param data expects: `struct`, `*struct`, `map[string]interface{}`.
func QueryPage ¶
QueryPage 分页查询 db需提供model和条件, list需提供切片地址 如 &[]yourStruct{} pg 如果均为默认参数,将不进行分页查询,将返回所有数据
func QueryPageAssociation ¶
func QueryPageAssociation(db *gorm.DB, pg paginator.Param, out interface{}, column string) (ifo paginator.Infos, err error)
QueryPageAssociation query page association
func QueryPageRelated ¶
func QueryPageRelated(db *gorm.DB, pg paginator.Param, out interface{}, foreignKeys ...string) error
QueryPageRelated 分页关联查询 db需提供model(并包含主键)和条件, list需提供切片地址 如 &[]yourStruct{} pg 如果均为默认参数,将不进行分页查询,将返回所有数据