sqlx

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: Unlicense Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDeleteWithoutCondition = errors.New("sha.sqlx: delete without condition")
View Source
var ErrEmptyConditionOrEmptyData = errors.New("sha.sqlx: empty condition or empty data")
View Source
var ErrImmutableField = errors.New("sha.sqlx: immutable field")
View Source
var ErrJsonValue = errors.New("sha.sqlx: json value error")
View Source
var ErrSubTx = errors.New("sha.sqlx: sub tx is invalid")
View Source
var PickReadonlyDB = func(dbs []*x.DB) *x.DB { return dbs[int(mrandlib.Uint32())%len(dbs)] }

Functions

func BindNamedArgs added in v0.0.5

func BindNamedArgs(exe Executor, q string, namedArgs interface{}) (string, []interface{})

func EnableLogging

func EnableLogging()

func OpenReadableDB

func OpenReadableDB(drivername, uri string)

func OpenWriteableDB

func OpenWriteableDB(driverName, uri string)

func SetLogger

func SetLogger(l *log.Logger)

func Tx

func Tx(ctx context.Context) (nctx context.Context, committer func())

Tx starts a transaction, return a sub context and a commit function

func UseWriteableDB

func UseWriteableDB(ctx context.Context) context.Context

Types

type Data

type Data map[string]interface{}

type Executor

type Executor interface {
	x.ExecerContext
	x.QueryerContext
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	PreparexContext(ctx context.Context, query string) (*x.Stmt, error)
	DriverName() string
	BindNamed(query string, arg interface{}) (string, []interface{}, error)
}

type JsonArray

type JsonArray []interface{}

func (*JsonArray) Scan

func (a *JsonArray) Scan(src interface{}) error

func (JsonArray) Value

func (a JsonArray) Value() (driver.Value, error)

type JsonObject

type JsonObject map[string]interface{}

func (*JsonObject) Scan

func (f *JsonObject) Scan(src interface{}) error

func (JsonObject) Value

func (f JsonObject) Value() (driver.Value, error)

type Model

type Model struct {
	ID      int64 `json:"id" db:"id,immutable,g=info"`
	Status  int   `json:"status" db:"status"`
	Created int64 `json:"created" db:"created,immutable,g=info"`
	Deleted int64 `json:"-" db:"deleted"`
}

func (Model) TableColumns

func (Model) TableColumns(db *sqlx.DB) []string

type Modeler

type Modeler interface {
	TableName() string
	TableColumns(db *sqlx.DB) []string
}

type Operator

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

func NewOperator

func NewOperator(ele Modeler) *Operator

func (*Operator) CreateTable

func (op *Operator) CreateTable()

func (*Operator) Delete

func (op *Operator) Delete(ctx context.Context, cond string, namedargs interface{}) sql.Result

func (*Operator) FetchMany

func (op *Operator) FetchMany(ctx context.Context, keysGroup string, condition string, arg interface{}, dist interface{}) error

func (*Operator) FetchOne

func (op *Operator) FetchOne(ctx context.Context, keysGroup string, condition string, namedargs interface{}, dist interface{}) error

func (*Operator) GroupColumns

func (op *Operator) GroupColumns(name string) []string

func (*Operator) GroupColumnsAppend added in v0.0.5

func (op *Operator) GroupColumnsAppend(name, val string)

func (*Operator) GroupColumnsRemove added in v0.0.5

func (op *Operator) GroupColumnsRemove(name, val string)

func (*Operator) Insert

func (op *Operator) Insert(ctx context.Context, data Data) int64

func (*Operator) InsertWithReturning

func (op *Operator) InsertWithReturning(ctx context.Context, data Data, returning string, dist ...interface{})

func (*Operator) IsImmutableField added in v0.0.5

func (op *Operator) IsImmutableField(f string) bool

func (*Operator) RowColumns

func (op *Operator) RowColumns(ctx context.Context, columns []string, cond string, namedargs interface{}, dist ...interface{}) error

func (*Operator) RowsColumn

func (op *Operator) RowsColumn(ctx context.Context, column string, cond string, namedargs interface{}, dist interface{}) error

func (*Operator) TableName

func (op *Operator) TableName() string

func (*Operator) Update

func (op *Operator) Update(ctx context.Context, data Data, condition string, namedargs interface{}) sql.Result

type Raw

type Raw string

type RollbackError

type RollbackError struct {
	RecoverVal interface{}
	Err        error
}

func (*RollbackError) Error

func (re *RollbackError) Error() string

type W

type W struct {
	Raw Executor
}

func Exe

func Exe(ctx context.Context) W

func (W) Exec

func (w W) Exec(ctx context.Context, q string, namedargs interface{}) sql.Result

exec

func (W) Get added in v0.0.5

func (w W) Get(ctx context.Context, q string, namedArgs interface{}, dist interface{}) error

func (W) ScanRow added in v0.0.5

func (w W) ScanRow(ctx context.Context, q string, namedargs interface{}, dist ...interface{}) error

scan

func (W) ScanRows added in v0.0.5

func (w W) ScanRows(ctx context.Context, q string, namedargs interface{}, scanner func(*sqlx.Rows) error) error

func (W) Select added in v0.0.5

func (w W) Select(ctx context.Context, q string, namedArgs interface{}, sliceDist interface{}) error

Jump to

Keyboard shortcuts

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