sqlxz

package module
v0.0.0-...-b1c7023 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

说明

GIN + ENT/SQLX + CASBIN + WIRE + I18N

为了保持系统精简性(目前数据库处理只使用SQLX), 暂时移除了ENT相关的内容, 结构暂时保留

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TBL = "zgo_"
)

Functions

func CreateUpdateSQLByNamed

func CreateUpdateSQLByNamed(tic TableIdxColumn, obj interface{},
	fix func(t reflect.Type, n string, v interface{}, f *reflect.StructField) (interface{}, bool),
	set func(c string, p map[string]interface{}, v interface{}, f *reflect.StructField) (string, bool),
) (string, map[string]interface{}, error)

CreateUpdateSQLByNamed create update sql by named

func CreateUpdateSQLByNamedAndSkipNil

func CreateUpdateSQLByNamedAndSkipNil(tic TableIdxColumn, obj interface{}) (string, map[string]interface{}, error)

CreateUpdateSQLByNamedAndSkipNil create update sql by named 忽略空字段, 空字段不进行更新, 如果需要前置更新空字段, 直接使用 CreateUpdateSQLByNamed

func CreateUpdateSQLByNamedAndSkipNilAndSet

func CreateUpdateSQLByNamedAndSkipNilAndSet(tic TableIdxColumn, obj interface{}) (string, map[string]interface{}, error)

CreateUpdateSQLByNamedAndSkipNilAndSet create update sql by named 会处理 "set" 标签的内容 , 比如 `set:"=cloumn + 1"`

func DeleteOne

func DeleteOne(sqlx *sqlx.DB, sql string, params ...interface{}) error

DeleteOne delete 1

func IsDuplicate

func IsDuplicate(err error) bool

func IsNotFound

func IsNotFound(err error) bool

IsNotFound of sqlx

func NewNowTime

func NewNowTime(t reflect.Type) interface{}

NewNowTime 获取当前时间

func PickProxy

func PickProxy(obj interface{}) interface{}

PickProxy 解除sql.NullXXX上的内容

func QueryGet

func QueryGet(sqlx EntityDB, srs interface{}, table, after string, sps ...interface{}) error

QueryGet 查询单个

func QueryGetTBL

func QueryGetTBL(sqlx EntityDB, srs interface{}, sql string, sps ...interface{}) error

QueryGet 查询单个

func QuerySelect

func QuerySelect(sqlx ArrayDB, srs interface{}, table, after string, sps ...interface{}) error

QuerySelect 查询集合

func QuerySelectDistinctTBL

func QuerySelectDistinctTBL(sqlx ArrayDB, srs interface{}, sql string, sps ...interface{}) error

QuerySelect 查询集合

func QuerySelectTBL

func QuerySelectTBL(sqlx ArrayDB, srs interface{}, sql string, sps ...interface{}) error

QuerySelect 查询集合

func SelectColumnX

func SelectColumnX(obj interface{}, pre string) string

SelectColumns select column

func SelectColumns

func SelectColumns(obj interface{}) string

SelectColumns select column

func Struct2Map

func Struct2Map(obj interface{}) map[string]interface{}

Struct2Map struct to map

func UpdateAndSaveByIDWithNamed

func UpdateAndSaveByIDWithNamed(sqlx *sqlx.DB, id *Index, fn func() (string, map[string]interface{}, error)) error

UpdateAndSaveByIDWithNamed update

func UpdateAndSaveTIC

func UpdateAndSaveTIC(sqlx ExecDB, srs interface{}, sic *TableIdxColumn, fres func(interface{})) (rsa int64, err error)

UpdateAndSaveX2 ...

func UpdateAndSaveX

func UpdateAndSaveX(sqlx ExecDB, srs interface{}, tbl string, sid int64, fid func(int64)) (rsa int64, err error)

UpdateAndSaveX ...

func WithTx

func WithTx(ctx context.Context, db *sqlx.DB, fn func(tx *sqlx.Tx) error) error

WithTx 执行带有事务的方法, 在一个事务中完成所有的内容

func WithTxV

func WithTxV(ctx context.Context, db *sqlx.DB, fn func(*sqlx.Tx) (interface{}, error)) (interface{}, error)

WithTxV 执行带有事务的方法, 在一个事务中完成所有的内容

func WithTxVx

func WithTxVx(ctx context.Context, db *sqlx.DB, rr interface{}, fn func(*sqlx.Tx, interface{}) (interface{}, error)) (interface{}, error)

WithTxVx 执行带有事务的方法, 在一个事务中完成所有的内容

Types

type ArrayDB

type ArrayDB interface {
	Select(dest interface{}, query string, args ...interface{}) error
}

type EntityDB

type EntityDB interface {
	Get(dest interface{}, query string, args ...interface{}) error
}

type ExecDB

type ExecDB interface {
	NamedExec(query string, arg interface{}) (sql.Result, error)
}

type Index

type Index struct {
	ID int64 `db:"id"`
}

Index id

type TableIdxColumn

type TableIdxColumn struct {
	Table  string
	IDCol  string      // index column
	IDVal  interface{} // index data
	Update sql.NullBool
	DB     *sqlx.DB
	IDCols []string               // index columns
	IDVals map[string]interface{} // index datas
}

TableIdxColumn id 1.Column="" 或者 Column = "id", 如果ID > 0 update, 否则 create 2.Update直接决定 update 或者 create 3.DB = nil 或者 Table = nil, 为 create 4.

Jump to

Keyboard shortcuts

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