zsql

package
v0.0.0-...-e6b4aba Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidModelsIterator = errors.New("invalid models iterator")

Functions

func WithRecovery

func WithRecovery(v func(exception interface{}) error) func(*txOption)

func WithRollback

func WithRollback(v func(rollback func() error, cause error) error) func(*txOption)

func WithSessionTx

func WithSessionTx(ctx context.Context, db DB, fn func(context.Context) error, onCommits ...func(ctx context.Context)) (err error)

func WithSqlTxOptions

func WithSqlTxOptions(v *sql.TxOptions) func(*txOption)

func WithTx

func WithTx(ctx context.Context, db DB, fn func(context.Context, Conn) error) (err error)

func WithTxOptions

func WithTxOptions(ctx context.Context, opts ...func(*txOption)) context.Context

Types

type Conn

type Conn interface {
	QueryContext(ctx context.Context, statement string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, statement string, args ...interface{}) *sql.Row
	ExecContext(ctx context.Context, statement string, args ...interface{}) (sql.Result, error)
	PrepareContext(ctx context.Context, statement string) (*sql.Stmt, error)
}

func SessionConn

func SessionConn(db DB, opts ...func(Conn) Conn) Conn

type DB

type DB interface {
	Close() error
	Stats() sql.DBStats
	PingContext(ctx context.Context) error
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
	Conn
}

type FieldMapping

type FieldMapping map[string]interface{}

func (FieldMapping) MapFields

func (mapping FieldMapping) MapFields(model Model, fp *[]string)

func (FieldMapping) MapValues

func (mapping FieldMapping) MapValues(fields []string, ptr *[]interface{})

type Litorm

type Litorm struct{ Conn }

func (Litorm) Insert

func (orm Litorm) Insert(ctx context.Context, ignore bool, model Model, fields []string, ext ...interface{}) (result sql.Result, err error)

func (Litorm) Inserts

func (orm Litorm) Inserts(ctx context.Context, ignore bool, models ModelIterator, fields []string, ext ...interface{}) (result sql.Result, err error)

func (Litorm) Select

func (orm Litorm) Select(ctx context.Context, model Model, fields []string, ext ...interface{}) (err error)

func (Litorm) Selects

func (orm Litorm) Selects(ctx context.Context, models ModelIterator, fields []string, ext ...interface{}) (err error)

func (Litorm) Update

func (orm Litorm) Update(ctx context.Context, model Model, fields []string, condition string, args ...interface{}) (result sql.Result, err error)

type Model

type Model interface {
	TableName() string
	FieldMapping(dst map[string]interface{})
}

type ModelIterator

type ModelIterator interface {
	Iterate(fn func(v interface{}, alloc bool) (next bool))
}

type SqlBuilder

type SqlBuilder struct{ strings.Builder }

func (*SqlBuilder) BuildInsert

func (bd *SqlBuilder) BuildInsert(models ModelIterator, ignore bool, fields []string, ext []interface{}) (args []interface{}, err error)

func (*SqlBuilder) BuildSelect

func (bd *SqlBuilder) BuildSelect(model Model, fields []string, ext []interface{}) (args []interface{})

func (*SqlBuilder) BuildUpdate

func (bd *SqlBuilder) BuildUpdate(model Model, fields []string, ext string, xargs []interface{}) (args []interface{})

func (*SqlBuilder) WriteExtArgs

func (bd *SqlBuilder) WriteExtArgs(ext []interface{}, args *[]interface{})

func (*SqlBuilder) WriteFields

func (bd *SqlBuilder) WriteFields(fields []string, name bool, suffix, sep string)

func (*SqlBuilder) WriteTable

func (bd *SqlBuilder) WriteTable(table string)

type StmtCacheConn

type StmtCacheConn struct {
	Conn Conn
	// contains filtered or unexported fields
}

func NewStmtCacher

func NewStmtCacher(conn Conn) *StmtCacheConn

func (*StmtCacheConn) Close

func (sc *StmtCacheConn) Close() error

func (*StmtCacheConn) ExecContext

func (sc *StmtCacheConn) ExecContext(ctx context.Context, statement string, args ...interface{}) (res sql.Result, err error)

func (*StmtCacheConn) PrepareContext

func (sc *StmtCacheConn) PrepareContext(ctx context.Context, statement string) (*sql.Stmt, error)

func (*StmtCacheConn) QueryContext

func (sc *StmtCacheConn) QueryContext(ctx context.Context, statement string, args ...interface{}) (rows *sql.Rows, err error)

func (*StmtCacheConn) QueryRowContext

func (sc *StmtCacheConn) QueryRowContext(ctx context.Context, statement string, args ...interface{}) *sql.Row

type Tx

type Tx interface {
	Conn
	driver.Tx
}

Jump to

Keyboard shortcuts

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