Documentation ¶
Index ¶
- Constants
- Variables
- func BindDriver(driverName string, bindType int)
- func BindNamed(bindType int, query string, arg interface{}) (string, []interface{}, error)
- func BindType(driverName string) int
- func CheckExists(ctx context.Context, db *DB, table string, params map[string]interface{}) (bool, error)
- func In(query string, args ...interface{}) (string, []interface{}, error)
- func IsDuplicate(err error) bool
- func IsMissingDb(err error) bool
- func Must(sc StoreChannel) interface{}
- func Named(query string, arg interface{}) (string, []interface{}, error)
- func Rebind(bindType int, query string) string
- type CommonDAO
- func (dao *CommonDAO) CalcSize(ctx context.Context, table string, params map[string]interface{}) int
- func (dao *CommonDAO) CalcSizeByWhere(ctx context.Context, table, where string) int
- func (dao *CommonDAO) CheckExists(ctx context.Context, table string, params map[string]interface{}) bool
- func (dao *CommonDAO) DB() *DB
- type Config
- type DB
- func (db *DB) Exec(c context.Context, query string, args ...interface{}) (res sql.Result, err error)
- func (db *DB) Master() *DB
- func (db *DB) NamedExec(c context.Context, query string, arg interface{}) (res sql.Result, err error)
- func (db *DB) NamedQueryRow(c context.Context, v interface{}, query string, arg interface{}) error
- func (db *DB) NamedQueryRowPartial(ctx context.Context, v interface{}, query string, arg interface{}) error
- func (db *DB) NamedQueryRows(c context.Context, v interface{}, query string, arg interface{}) error
- func (db *DB) NamedQueryRowsPartial(c context.Context, v interface{}, query string, arg interface{}) (err error)
- func (db *DB) Prepare(c context.Context, query string) (sqlx.StmtSession, error)
- func (db *DB) QueryRow(c context.Context, v interface{}, query string, args ...interface{}) (err error)
- func (db *DB) QueryRowPartial(c context.Context, v interface{}, query string, args ...interface{}) error
- func (db *DB) QueryRows(c context.Context, v interface{}, query string, args ...interface{}) (err error)
- func (db *DB) QueryRowsPartial(c context.Context, v interface{}, query string, args ...interface{}) (err error)
- func (db *DB) Transact(ctx context.Context, fn func(*Tx) error) error
- type ExecResult
- type StoreChannel
- type StoreResult
- type Tx
- func (tx *Tx) Context() context.Context
- func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error)
- func (tx *Tx) NamedExec(query string, arg interface{}) (sql.Result, error)
- func (tx *Tx) NamedQueryRow(v interface{}, query string, arg interface{}) error
- func (tx *Tx) NamedQueryRowPartial(v interface{}, query string, arg interface{}) error
- func (tx *Tx) NamedQueryRows(v interface{}, query string, arg interface{}) error
- func (tx *Tx) NamedQueryRowsPartial(v interface{}, query string, arg interface{}) error
- func (tx *Tx) Prepare(query string) (sqlx.StmtSession, error)
- func (tx *Tx) QueryRow(v interface{}, query string, args ...interface{}) error
- func (tx *Tx) QueryRowPartial(v interface{}, query string, args ...interface{}) error
- func (tx *Tx) QueryRows(v interface{}, query string, args ...interface{}) error
- func (tx *Tx) QueryRowsPartial(v interface{}, query string, args ...interface{}) error
Constants ¶
const ( UNKNOWN = iota QUESTION DOLLAR NAMED AT )
Bindvar types supported by Rebind, BindMap and BindStruct.
Variables ¶
var ( DeletedNo int64 = 0 DeletedYes int64 = 1 )
soft delete flag
var ( // // ErrStmtNil prepared stmt error // ErrStmtNil = errors.New("sql: prepare failed and stmt nil") // ErrNoMaster is returned by Master when call master multiple times. ErrNoMaster = errors.New("sql: no master instance") )
var (
ErrNotFound = sql.ErrNoRows
)
var NameMapper = strings.ToLower
NameMapper is used to map column names to struct field names. By default, it uses strings.ToLower to lowercase struct field names. It can be set to whatever you want, but it is encouraged to be set before sqlx is used as name-to-field mappings are cached after first use on a type.
Functions ¶
func BindDriver ¶
BindDriver sets the BindType for driverName to bindType.
func BindNamed ¶
BindNamed binds a struct or a map to a query with named parameters. DEPRECATED: use sqlx.Named` instead of this, it may be removed in future.
func CheckExists ¶
func CheckExists(ctx context.Context, db *DB, table string, params map[string]interface{}) (bool, error)
CheckExists 检查是否存在
func In ¶
In expands slice values in args, returning the modified query string and a new arg list that can be executed by a database. The `query` should use the `?` bindVar. The return value uses the `?` bindVar.
func IsDuplicate ¶
IsDuplicate Check if MySQL error is a Error Code: 1062. Duplicate entry ... for key ...
func Must ¶
func Must(sc StoreChannel) interface{}
Types ¶
type CommonDAO ¶
type CommonDAO struct {
// contains filtered or unexported fields
}
func NewCommonDAO ¶
func (*CommonDAO) CalcSizeByWhere ¶
type Config ¶
type Config struct { DSN string // write data source name. ReadDSN []string `json:",optional"` // read data source name. Active int `json:",optional"` // pool Idle int `json:",optional"` // pool IdleTimeout string `json:",optional"` // connect max life time. }
Config mysql config.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB database.
func Open ¶
Open opens a database specified by its database driver name and a driver-specific data source name, usually consisting of at least a database name and connection information.
func (*DB) Exec ¶
func (db *DB) Exec(c context.Context, query string, args ...interface{}) (res sql.Result, err error)
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*DB) Master ¶
Master return *DB instance direct use master conn use this *DB instance only when you have some reason need to get result without any delay.
func (*DB) NamedExec ¶
func (db *DB) NamedExec(c context.Context, query string, arg interface{}) (res sql.Result, err error)
NamedExec using this DB. Any named placeholder parameters are replaced with fields from arg.
func (*DB) NamedQueryRow ¶
NamedQueryRow using this DB. Any named placeholder parameters are replaced with fields from arg.
func (*DB) NamedQueryRowPartial ¶
func (*DB) NamedQueryRows ¶
func (*DB) NamedQueryRowsPartial ¶
func (*DB) Prepare ¶
Prepare creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's Close method when the statement is no longer needed.
func (*DB) QueryRow ¶
func (db *DB) QueryRow(c context.Context, v interface{}, query string, args ...interface{}) (err error)
QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called.
func (*DB) QueryRowPartial ¶
func (*DB) QueryRows ¶
func (db *DB) QueryRows(c context.Context, v interface{}, query string, args ...interface{}) (err error)
QueryRows executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DB) QueryRowsPartial ¶
type ExecResult ¶
type StoreChannel ¶
type StoreChannel chan StoreResult
func Do ¶
func Do(f func(result *StoreResult)) StoreChannel
type StoreResult ¶
func TxWrapper ¶
func TxWrapper(ctx context.Context, db *DB, txF func(*Tx, *StoreResult)) *StoreResult
TxWrapper TxWrapper
type Tx ¶
func (*Tx) NamedExec ¶
NamedExec using this DB. Any named placeholder parameters are replaced with fields from arg.
func (*Tx) NamedQueryRow ¶
NamedQueryRow using this DB. Any named placeholder parameters are replaced with fields from arg.
func (*Tx) NamedQueryRowPartial ¶
func (*Tx) NamedQueryRows ¶
func (*Tx) NamedQueryRowsPartial ¶
func (*Tx) QueryRowPartial ¶
func (*Tx) QueryRowsPartial ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package reflectx implements extensions to the standard reflect lib suitable for implementing marshalling and unmarshalling packages.
|
Package reflectx implements extensions to the standard reflect lib suitable for implementing marshalling and unmarshalling packages. |