iorm

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

Package iorm

Index

Constants

View Source
const (
	MySQL    = "mysql"
	Postgres = "postgres"
)

Variables

View Source
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 GetDB

func GetDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

GetDB get db

func GetDBWithModel

func GetDBWithModel(ctx context.Context, defDB *gorm.DB, model interface{}) *gorm.DB

GetDBWithModel get db with model

func InsertSQL

func InsertSQL(table string, data interface{}) (sql string, binds []interface{})

InsertSQL returns mysql insert sql and binds. param data expects: `struct`, `*struct`, `[]struct`, `[]*struct`, `map[string]interface{}`, `[]map[string]interface{}`.

func PGInsertSQL

func PGInsertSQL(table string, data interface{}) (sql string, binds []interface{})

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 QueryOne

func QueryOne(db *gorm.DB, query map[string]interface{}, out interface{}) error

QueryOne 根据id更新相应字段

func QueryPage

func QueryPage(db *gorm.DB, pg paginator.Param, out interface{}) (paginator.Infos, error)

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 如果均为默认参数,将不进行分页查询,将返回所有数据

func Update

func Update(db *gorm.DB, id uint, attrs ...interface{}) error

Update 根据id更新相应字段, db需提供model

func UpdateAny

func UpdateAny(db *gorm.DB, query map[string]interface{}, attrs ...interface{}) error

UpdateAny 根据query条件,更新相应字段, db需提供model

func UpdateSQL

func UpdateSQL(query string, data interface{}, args ...interface{}) (sql string, binds []interface{})

UpdateSQL returns mysql update sql and binds. param query expects eg: "UPDATE `table` SET ? WHERE `id` = ?". param data expects: `struct`, `*struct`, `map[string]interface{}`.

Types

type M

type M map[string]interface{}

M 别名

Directories

Path Synopsis
Package trans gorm 事务封装
Package trans gorm 事务封装

Jump to

Keyboard shortcuts

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