database

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBO

type DBO struct {
	// contains filtered or unexported fields
}

func New

func New(dial string, logger *zap.Logger) *DBO

func (*DBO) Delete

func (dbo *DBO) Delete(ctx context.Context, tx *sql.Tx, table string, where []Where) (sql.Result, error)

Delete delete records

func (*DBO) Excute

func (dbo *DBO) Excute(ctx context.Context, stmt *sql.Stmt, fields []Feild) (sql.Result, error)

func (*DBO) Exec

func (dbo *DBO) Exec(ctx context.Context, tx *sql.Tx, query string, args ...any) (sql.Result, error)

func (*DBO) Insert

func (dbo *DBO) Insert(ctx context.Context, tx *sql.Tx, table string, fields []Feild) (sql.Result, error)

func (*DBO) Prepare

func (dbo *DBO) Prepare(ctx context.Context, tx *sql.Tx, table string, fields []Feild) (*sql.Stmt, error)

func (*DBO) SelectRawSQL

func (dbo *DBO) SelectRawSQL(ctx context.Context, table string, sqlStr string, values []interface{}, result interface{}) error

SelectRawSQL query useing raw sql

func (*DBO) SelectRows

func (dbo *DBO) SelectRows(ctx context.Context, table string, cols []string, where []Where, order *Order, paging *Paging, result interface{}) error

SelectRows select rows to struct slice

func (*DBO) SelectRowsOffset

func (dbo *DBO) SelectRowsOffset(ctx context.Context, table string, cols []string, where []Where, order *Order, offset, limit uint64, result interface{}) error

SelectRowsOffset select rows to struct slice

func (*DBO) SelectRowsToMaps

func (dbo *DBO) SelectRowsToMaps(ctx context.Context, table string, cols []string, where []Where, order *Order, paging *Paging) ([]map[string]interface{}, error)

SelectRowsToMaps select rows to map slice

func (*DBO) SelectRowsUnion

func (dbo *DBO) SelectRowsUnion(ctx context.Context, table string, cols []string, wheres [][]Where, order *Order, paging *Paging, result interface{}) error

func (*DBO) SelectRowsUnionToMaps added in v0.1.8

func (dbo *DBO) SelectRowsUnionToMaps(ctx context.Context, table string, cols []string, wheres [][]Where, order *Order, paging *Paging) ([]map[string]interface{}, error)

func (*DBO) Transaction

func (dbo *DBO) Transaction(fn func(tx *sql.Tx) error) error

func (*DBO) Update

func (dbo *DBO) Update(ctx context.Context, tx *sql.Tx, table string, toupdate []Feild, where []Where) (sql.Result, error)

Update update records

type Feild

type Feild struct {
	Name  string
	Value interface{}
}

Feild database field

type Order

type Order struct {
	Type   string   // "asc" or "desc"
	Feilds []string // order by x
}

Order used to identify query order

func MakeOrder

func MakeOrder(ordertype string, fields ...string) (*Order, error)

MakeOrder make a order object

func (*Order) GetOp

func (o *Order) GetOp() string

GetOp used in sql

type Paging

type Paging struct {
	CursorName  string // cursor column
	CursorValue uint64 // cursor column
	Limit       uint64 // limit
}

func MakePaging

func MakePaging(colName string, colValue uint64, limit uint64) *Paging

MakePaging make a paging object

type Where

type Where struct {
	Name  string
	Value interface{}
	Op    string // can be =、>、<、<> and any operator supported by sql-database
}

Where query field

func (*Where) GetOp

func (w *Where) GetOp() string

GetOp get operator of current where clause, default =

Jump to

Keyboard shortcuts

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