Documentation ¶
Index ¶
- Variables
- type Config
- type DB
- func (db *DB) Begin(c context.Context) (tx *Tx, err error)
- func (db *DB) Close() (err error)
- func (db *DB) Exec(c context.Context, query string, args ...interface{}) (res sql.Result, err error)
- func (db *DB) Master() *DB
- func (db *DB) Ping(c context.Context) (err error)
- func (db *DB) Prepare(query string) (*Stmt, error)
- func (db *DB) Prepared(query string) (stmt *Stmt)
- func (db *DB) Query(c context.Context, query string, args ...interface{}) (rows *Rows, err error)
- func (db *DB) QueryRow(c context.Context, query string, args ...interface{}) *Row
- type DataType
- type Field
- type Model
- func (m *Model) Begin(c context.Context) (err error)
- func (m *Model) Commit() (err error)
- func (m *Model) Exec(c context.Context, query string, args ...interface{}) (res sql.Result, err error)
- func (m *Model) Query(c context.Context, query string, args ...interface{}) (*Rows, error)
- func (m *Model) QueryRow(c context.Context, query string, args ...interface{}) *Row
- func (m *Model) Rollback() (err error)
- func (m *Model) Select(c context.Context, dest interface{}, query string, args ...interface{}) (err error)
- type Row
- type Rows
- type Stmt
- type TimeType
- type Tx
- func (tx *Tx) Commit() (err error)
- func (tx *Tx) Exec(query string, args ...interface{}) (res sql.Result, err error)
- func (tx *Tx) Prepare(c context.Context, query string) (*Stmt, error)
- func (tx *Tx) Query(query string, args ...interface{}) (rows *Rows, err error)
- func (tx *Tx) QueryRow(query string, args ...interface{}) *Row
- func (tx *Tx) Rollback() (err error)
- func (tx *Tx) Stmt(stmt *Stmt) *Stmt
Constants ¶
This section is empty.
Variables ¶
var ( //ErrNoPtr .. ErrNoPtr = errors.New("noptr") //ErrNoResult .. ErrNoResult = errors.New("noResult") )
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") // ErrNoRows is returned by Scan when QueryRow doesn't return a row. // In such a case, QueryRow returns a placeholder *Row value that defers // this error until a Scan. ErrNoRows = sql.ErrNoRows // ErrTxDone transaction done. ErrTxDone = sql.ErrTxDone )
var TimeReflectType = reflect.TypeOf(time.Time{})
TimeReflectType ..
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { DSN string `yaml:"DSN"` // write data source name. ReadDSN []string `yaml:"ReadDSN"` // read data source name. Active int `yaml:"Active"` // pool Idle int `yaml:"Idle"` // pool IdleTimeout time.Duration `yaml:"IdleTimeout"` // connect max life time. QueryTimeout time.Duration `yaml:"QueryTimeout"` // query sql timeout ExecTimeout time.Duration `yaml:"ExecTimeout"` // execute sql timeout TranTimeout time.Duration `yaml:"TranTimeout"` // transaction sql timeout }
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) Ping ¶
Ping verifies a connection to the database is still alive, establishing a connection if necessary.
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) Prepared ¶
Prepared 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.
type Model ¶ added in v1.2.5
Model ..
func (*Model) Begin ¶ added in v1.2.5
Begin starts a transaction. The isolation level is dependent on the driver.
func (*Model) Exec ¶ added in v1.2.5
func (m *Model) 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 (*Model) Query ¶ added in v1.2.5
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*Model) QueryRow ¶ added in v1.2.5
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.
type Rows ¶
Rows rows.
type Stmt ¶
type Stmt struct {
// contains filtered or unexported fields
}
Stmt prepared stmt.
func (*Stmt) Exec ¶
Exec executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
func (*Stmt) Query ¶
Query executes a prepared query statement with the given arguments and returns the query results as a *Rows.
func (*Stmt) QueryRow ¶
QueryRow executes a prepared query statement with the given arguments. If an error occurs during the execution of the statement, that error will be returned by a call to Scan on the returned *Row, which is always non-nil. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx transaction.
func (*Tx) Exec ¶
Exec executes a query that doesn't return rows. For example: an INSERT and UPDATE.
func (*Tx) Prepare ¶
Prepare creates a prepared statement for use within a transaction. The returned statement operates within the transaction and can no longer be used once the transaction has been committed or rolled back. To use an existing prepared statement on this transaction, see Tx.Stmt.