Documentation ¶
Index ¶
- type DB
- func (db *DB) Begin() (*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) Master() *sql.DB
- func (db *DB) Ping() error
- func (db *DB) Prepare(query string) (Stmt, error)
- func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (db *DB) QueryRow(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 {
// 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) 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) Ping ¶
Ping 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) 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) 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) 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).