Documentation ¶
Index ¶
- type DB
- func (db *DB) Begin() (*sqlx.Tx, error)
- func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sqlx.Tx, error)
- func (db *DB) Close() error
- func (db *DB) Driver() driver.Driver
- func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (db *DB) Master() *sqlx.DB
- func (db *DB) Ping() error
- func (db *DB) PingContext(ctx context.Context) error
- func (db *DB) Preparex(query string) (*sqlx.Stmt, error)
- func (db *DB) PreparexContext(ctx context.Context, query string) (*sqlx.Stmt, error)
- func (db *DB) PreparexSlave(query string) (*sqlx.Stmt, error)
- func (db *DB) PreparexSlaveContext(ctx context.Context, query string) (*sqlx.Stmt, error)
- func (db *DB) QueryxSlave(query string, args ...interface{}) (*sqlx.Rows, error)
- func (db *DB) QueryxSlaveContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
- func (db *DB) Select(dest interface{}, query string, args ...interface{}) error
- func (db *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (db *DB) SetConnMaxLifetime(d time.Duration)
- func (db *DB) SetMaxIdleConns(n int)
- func (db *DB) SetMaxOpenConns(n int)
- func (db *DB) Slave() *sqlx.DB
- type Stmt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a logical database with multiple underlying physical databases forming a single master multiple slaves topology. Reads and writes are automatically directed to the correct physical db.
func Open ¶
Open concurrently opens each underlying physical db. dataSourceNames must be a semi-comma separated list of DSNs with the first one being used as the master and the rest as slaves.
func (*DB) Begin ¶
Begin starts a transaction on the master. The isolation level is dependent on the driver.
func (*DB) BeginTx ¶
BeginTx starts a transaction with the provided context on the master.
The provided TxOptions is optional and may be nil if defaults should be used. If a non-default isolation level is used that the driver doesn't support, an error will be returned.
func (*DB) Exec ¶
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query. Exec uses the master as the underlying physical db.
func (*DB) ExecContext ¶
func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query. Exec uses the master as the underlying physical db.
func (*DB) Ping ¶
Ping verifies if a connection to each physical database is still alive, establishing a connection if necessary.
func (*DB) PingContext ¶
PingContext verifies if a connection to each physical database is still alive, establishing a connection if necessary.
func (*DB) PreparexContext ¶
func (*DB) PreparexSlave ¶
PreparexSlave prepares a statement that connects with one of the slaves.
func (*DB) PreparexSlaveContext ¶
func (*DB) QueryxSlave ¶
QueryxSlave performs an sqlx Queryx call against one of the slaves.
func (*DB) QueryxSlaveContext ¶
func (*DB) SelectContext ¶
func (*DB) SetConnMaxLifetime ¶
SetConnMaxLifetime sets the maximum amount of time a connection may be reused. Expired connections may be closed lazily before reuse. If d <= 0, connections are reused forever.
func (*DB) SetMaxIdleConns ¶
SetMaxIdleConns sets the maximum number of connections in the idle connection pool for each underlying physical db. If MaxOpenConns is greater than 0 but less than the new MaxIdleConns then the new MaxIdleConns will be reduced to match the MaxOpenConns limit If n <= 0, no idle connections are retained.
func (*DB) SetMaxOpenConns ¶
SetMaxOpenConns sets the maximum number of open connections to each physical database. If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than MaxIdleConns, then MaxIdleConns will be reduced to match the new MaxOpenConns limit. If n <= 0, then there is no limit on the number of open connections. The default is 0 (unlimited).