Documentation ¶
Index ¶
- type DB
- func (db *DB) Begin() (*sql.Tx, error)
- func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.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() *sql.DB
- func (db *DB) Ping() error
- func (db *DB) PingContext(ctx context.Context) error
- func (db *DB) Prepare(query string) (Stmt, error)
- func (db *DB) PrepareContext(ctx context.Context, query string) (Stmt, error)
- func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (db *DB) QueryRow(query string, args ...interface{}) *sql.Row
- func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (db *DB) SetConnMaxLifetime(d time.Duration)
- func (db *DB) SetMaxIdleConns(n int)
- func (db *DB) SetMaxOpenConns(n int)
- func (db *DB) Slave() *sql.DB
- type Stmt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct { Pdbs []*sql.DB // Physical databases Count uint64 // Monotonically incrementing counter on each query }
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) Prepare ¶
Prepare creates a prepared statement for later queries or executions on each physical database, concurrently.
func (*DB) PrepareContext ¶
PrepareContext creates a prepared statement for later queries or executions on each physical database, concurrently.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (*DB) Query ¶
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query. Query uses a slave as the physical db.
func (*DB) QueryContext ¶
func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query. QueryContext uses a slave as the physical db.
func (*DB) QueryRow ¶
QueryRow executes a query that is expected to return at most one row. QueryRow always return a non-nil value. Errors are deferred until Row's Scan method is called. QueryRow uses a slave as the physical db.
func (*DB) QueryRowContext ¶
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always return a non-nil value. Errors are deferred until Row's Scan method is called. QueryRowContext uses a slave as the physical db.
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).