Documentation ¶
Index ¶
- Constants
- Variables
- func Exec(query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error)
- func ExecContext(ctx context.Context, query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error)
- func Get(dest interface{}, query string, args ...interface{}) (err error)
- func Int64ArrayToIn(arrs []int64) string
- func IsolationDefault(readOnly bool) *sql.TxOptions
- func IsolationLinearizable(readOnly bool) *sql.TxOptions
- func IsolationReadCommitted(readOnly bool) *sql.TxOptions
- func IsolationReadUncommitted(readOnly bool) *sql.TxOptions
- func IsolationRepeatableRead(readOnly bool) *sql.TxOptions
- func IsolationSerializable(readOnly bool) *sql.TxOptions
- func IsolationSnapshot(readOnly bool) *sql.TxOptions
- func IsolationWriteCommitted(readOnly bool) *sql.TxOptions
- func NamedExec(query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
- func NamedExecContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
- func NewNamedStmt() *sqlx.NamedStmt
- func Ping() (err error)
- func PingContext(ctx context.Context) (err error)
- func PutNamedStmt(stmt *sqlx.NamedStmt)
- func Query(dest interface{}, query string, args interface{}) (err error)
- func QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
- func QueryRow(dest interface{}, query string, args interface{}) (err error)
- func QueryRowContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
- func Release()
- func ReleaseConfig(dbx *DB)
- func ReplyToReplyData(reply Reply) *myth.ReplyData
- func Row(dest interface{}, query string, args interface{}) (err error)
- func RowContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
- func Rows(dest interface{}, query string, args interface{}) (err error)
- func RowsContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
- func Select(dest interface{}, query string, args ...interface{}) (err error)
- func SetConfig(cfg Config)
- func Stats() (s sql.DBStats, err error)
- type Config
- type DB
- func (d *DB) Begin() (tx *Tx, err error)
- func (d *DB) BeginTrans() (err error)
- func (d *DB) BeginTransx(ctx context.Context, opts *sql.TxOptions) (err error)
- func (d *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (tx *Tx, err error)
- func (d *DB) Close()
- func (d *DB) Commit() (err error)
- func (d *DB) Connect() (err error)
- func (d *DB) ConnectContext(ctx context.Context) (err error)
- func (d *DB) Exec(query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error)
- func (d *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error)
- func (d *DB) Get(dest interface{}, query string, args ...interface{}) (err error)
- func (d *DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
- func (d *DB) In(query string, args ...interface{}) (q string, params []interface{}, err error)
- func (d *DB) Insert(query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
- func (d *DB) InsertContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
- func (d *DB) InsertReply(query string, args interface{}) (reply Reply)
- func (d *DB) Limit(page, pagesize int) string
- func (d *DB) NamedExec(query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
- func (d *DB) NamedExecContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
- func (d *DB) Ping() (err error)
- func (d *DB) PingContext(ctx context.Context) (err error)
- func (d *DB) PrepareNamed(query string) (stmt *NamedStmt, err error)
- func (d *DB) PrepareNamedContext(ctx context.Context, query string) (stmt *NamedStmt, err error)
- func (d *DB) Preparex(query string) (stmt *Stmt, err error)
- func (d *DB) PreparexContext(ctx context.Context, query string) (stmt *Stmt, err error)
- func (d *DB) Query(dest interface{}, query string, args interface{}) (err error)
- func (d *DB) QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
- func (d *DB) QueryRow(dest interface{}, query string, args ...interface{}) (err error)
- func (d *DB) QueryRowContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
- func (d *DB) Rollback() (err error)
- func (d *DB) Row(dest interface{}, query string, args interface{}) (err error)
- func (d *DB) RowContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
- func (d *DB) Rows(dest interface{}, query string, args interface{}) (err error)
- func (d *DB) RowsContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
- func (d *DB) Select(dest interface{}, query string, args ...interface{}) (err error)
- func (d *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
- func (d *DB) Stats() (s sql.DBStats)
- func (d *DB) TransExec(query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
- func (d *DB) TransExecContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
- func (d *DB) TransRow(dest interface{}, query string, args interface{}) (err error)
- func (d *DB) TransUpdate(query string, args interface{}) (reply Reply)
- func (d *DB) Update(query string, args interface{}) (rowsAffected int64, err error)
- func (d *DB) UpdateContext(ctx context.Context, query string, args interface{}) (rowsAffected int64, err error)
- func (d *DB) UpdateReply(query string, args interface{}) (reply Reply)
- type M
- type NamedStmt
- type Reply
- type Stmt
- type Tx
- func (t *Tx) Commit() error
- func (t *Tx) Exec(query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error)
- func (t *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error)
- func (t *Tx) NamedExec(query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
- func (t *Tx) NamedExecContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
- func (t *Tx) PrepareNamed(query string) (stmt *NamedStmt, err error)
- func (t *Tx) PrepareNamedContext(ctx context.Context, query string) (stmt *NamedStmt, err error)
- func (t *Tx) Preparex(query string) (stmt *Stmt, err error)
- func (t *Tx) PreparexContext(ctx context.Context, query string) (stmt *Stmt, err error)
- func (t *Tx) Query(dest interface{}, query string, args interface{}) (err error)
- func (t *Tx) QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
- func (t *Tx) QueryRow(dest interface{}, query string, args interface{}) (err error)
- func (t *Tx) QueryRowContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
- func (t *Tx) Rollback() error
Constants ¶
const ( // ErrOK ok ErrOK = 0 // ErrException exception 异常 ErrException = 1 // ErrExists exists 数据存在 ErrExists = 2 // ErrNotFound not found 未找到关键数据 ErrNotFound = 3 // ErrAuthorized authorized 未认证 ErrAuthorized = 4 // ErrNotConnect connect error 数据库内部连接错误 ErrNotConnect = 5 // data not found 数据未找到 ErrDataNotFound = 6 // expired 已过期 ErrExpired = 7 // insufficient balance 余额不足 ErrInsufficientBalance = 8 // Credit Limit 超额 ErrCreditLimit = 9 )
DB error code
Variables ¶
var (
ErrNoneConnect = errors.New(`not connect to database`)
)
Functions ¶
func ExecContext ¶
func ExecContext(ctx context.Context, query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error)
Exec exec
func IsolationLinearizable ¶
IsolationLinearizable
func IsolationReadCommitted ¶
IsolationReadCommitted
func IsolationReadUncommitted ¶
IsolationReadUncommitted
func IsolationRepeatableRead ¶
IsolationRepeatableRead
func IsolationSerializable ¶
IsolationSerializable
func IsolationWriteCommitted ¶
IsolationWriteCommitted
func NamedExecContext ¶
func NamedExecContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
NamedExecContext exec with named args
func NewNamedStmt ¶
NewNamedStmt alloc *sqlx.NamedStmt from pool
func PutNamedStmt ¶
PutNamedStmt release *sqlx.NamedStmt to pool
func QueryContext ¶
func QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
QueryContext get rows with named args
func QueryRowContext ¶
func QueryRowContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
QueryRowContext get row with named args
func ReplyToReplyData ¶
ReplyToReplyData db reply to response
func RowContext ¶
RowContext get row with named args
func RowsContext ¶
RowsContext get rows with named args
Types ¶
type Config ¶
type Config struct { Driver string DNS string MaxOpenConns int MaxIdle int MaxIdleTime time.Duration MaxLifeTime time.Duration }
Config config
type DB ¶
type DB struct { Driver string // contains filtered or unexported fields }
DB define
func (*DB) Begin ¶
Begin starts a transaction. The default isolation level is dependent on the driver.
func (*DB) BeginTransx ¶
BeginTransx begin trans
func (*DB) ConnectContext ¶
ConnectContext connect to database
func (*DB) ExecContext ¶
func (d *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error)
ExecContext exec
func (*DB) GetContext ¶
func (d *DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
GetContext get
func (*DB) 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 (*DB) InsertContext ¶
func (d *DB) InsertContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
InsertContext insert into with named args
func (*DB) InsertReply ¶
InsertReply insert and return DbReply
func (*DB) NamedExec ¶
func (d *DB) NamedExec(query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
Exec exec, with named args
func (*DB) NamedExecContext ¶
func (d *DB) NamedExecContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
NamedExecContext exec, with named args
func (*DB) PingContext ¶
PingContext Ping connect
func (*DB) PrepareNamed ¶
PrepareNamed returns an sqlx.NamedStmt
func (*DB) PrepareNamedContext ¶
PrepareNamedContext returns an sqlx.NamedStmt
func (*DB) PreparexContext ¶
PreparexContext returns an sqlx.Stmt instead of a sql.Stmt.
func (*DB) Query ¶
Query get rows with named args, Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DB) QueryContext ¶
func (d *DB) QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
QueryContext get rows with named args, QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DB) QueryRow ¶
QueryRow get row, QueryRow executes a query that is expected to return at most one row.
func (*DB) QueryRowContext ¶
func (d *DB) QueryRowContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
QueryRowContext get row, QueryRowContext executes a query that is expected to return at most one row.
func (*DB) RowContext ¶
func (d *DB) RowContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
RowContext get row with named args
func (*DB) RowsContext ¶
func (d *DB) RowsContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
RowsContext get rows with named args
func (*DB) SelectContext ¶
func (d *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
SelectContext select
func (*DB) TransExec ¶
func (d *DB) TransExec(query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
TransExec trans execute with named args
func (*DB) TransExecContext ¶
func (d *DB) TransExecContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
TransExec trans execute with named args
func (*DB) TransUpdate ¶
TransUpdate trans update
func (*DB) UpdateContext ¶
func (d *DB) UpdateContext(ctx context.Context, query string, args interface{}) (rowsAffected int64, err error)
Update update/delete with named args
func (*DB) UpdateReply ¶
UpdateReply update/delete and return DbReply
type M ¶
M is a shortcut for map[string]any
func (M) MarshalXML ¶
MarshalXML allows type Map to be used with xml.Marshal.
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is an in-progress database transaction.
func (*Tx) Exec ¶
Exec executes a query that doesn't return rows. For example: an INSERT and UPDATE.
func (*Tx) ExecContext ¶
func (t *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (lastInsertId, rowsAffected int64, err error)
ExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE.
func (*Tx) NamedExec ¶
func (t *Tx) NamedExec(query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
NamedExec executes a query that doesn't return rows. For example: an INSERT and UPDATE. with named args
func (*Tx) NamedExecContext ¶
func (t *Tx) NamedExecContext(ctx context.Context, query string, args interface{}) (lastInsertId, rowsAffected int64, err error)
NamedExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE. with named args
func (*Tx) PrepareNamed ¶
PrepareNamed returns an sqlx.NamedStmt
func (*Tx) PrepareNamedContext ¶
PrepareNamedContext returns an sqlx.NamedStmt
func (*Tx) PreparexContext ¶
PreparexContext a statement within a transaction.
func (*Tx) QueryContext ¶
func (t *Tx) QueryContext(ctx context.Context, dest interface{}, query string, args interface{}) (err error)
QueryContext executes a query that returns rows, typically a SELECT. with named args
func (*Tx) QueryRow ¶
QueryRow executes a query that returns rows, typically a SELECT. with named args