Documentation ¶
Index ¶
- Constants
- Variables
- type DBs
- func (dbs *DBs) Begin() (*sql.Tx, error)
- func (dbs *DBs) BeginTx(ctx context.Context, opts *sql.TxOptions) (res *sql.Tx, err error)
- func (dbs *DBs) BeginTxx(ctx context.Context, opts *sql.TxOptions) (res *sqlx.Tx, err error)
- func (dbs *DBs) Beginx() (res *sqlx.Tx, err error)
- func (dbs *DBs) BindNamed(query string, arg interface{}) (string, []interface{}, error)
- func (dbs *DBs) Destroy() []error
- func (dbs *DBs) DestroyMaster() []error
- func (dbs *DBs) DestroySlave() []error
- func (dbs *DBs) DriverName() string
- func (dbs *DBs) Exec(query string, args ...interface{}) (sql.Result, error)
- func (dbs *DBs) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (dbs *DBs) ExecContextOnSlave(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (dbs *DBs) ExecOnSlave(query string, args ...interface{}) (sql.Result, error)
- func (dbs *DBs) Get(dest interface{}, query string, args ...interface{}) (err error)
- func (dbs *DBs) GetAllMasters() ([]*sqlx.DB, int)
- func (dbs *DBs) GetAllSlaves() ([]*sqlx.DB, int)
- func (dbs *DBs) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
- func (dbs *DBs) GetContextOnMaster(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
- func (dbs *DBs) GetOnMaster(dest interface{}, query string, args ...interface{}) (err error)
- func (dbs *DBs) MapperFunc(mf func(string) string)
- func (dbs *DBs) MapperFuncMaster(mf func(string) string)
- func (dbs *DBs) MapperFuncSlave(mf func(string) string)
- func (dbs *DBs) MustBegin() *sql.Tx
- func (dbs *DBs) MustBeginTx(ctx context.Context, opts *sql.TxOptions) *sqlx.Tx
- func (dbs *DBs) MustBeginx() *sqlx.Tx
- func (dbs *DBs) MustExec(query string, args ...interface{}) sql.Result
- func (dbs *DBs) MustExecContext(ctx context.Context, query string, args ...interface{}) sql.Result
- func (dbs *DBs) MustExecContextOnSlave(ctx context.Context, query string, args ...interface{}) sql.Result
- func (dbs *DBs) MustExecOnSlave(query string, args ...interface{}) sql.Result
- func (dbs *DBs) NamedExec(query string, arg interface{}) (sql.Result, error)
- func (dbs *DBs) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
- func (dbs *DBs) NamedExecContextOnSlave(ctx context.Context, query string, arg interface{}) (sql.Result, error)
- func (dbs *DBs) NamedExecOnSlave(query string, arg interface{}) (sql.Result, error)
- func (dbs *DBs) NamedQuery(query string, arg interface{}) (*sqlx.Rows, error)
- func (dbs *DBs) NamedQueryContext(ctx context.Context, query string, arg interface{}) (*sqlx.Rows, error)
- func (dbs *DBs) NamedQueryContextOnMaster(ctx context.Context, query string, arg interface{}) (*sqlx.Rows, error)
- func (dbs *DBs) NamedQueryOnMaster(query string, arg interface{}) (*sqlx.Rows, error)
- func (dbs *DBs) Ping() []error
- func (dbs *DBs) PingMaster() []error
- func (dbs *DBs) PingSlave() []error
- func (dbs *DBs) Prepare(query string) (db *sqlx.DB, stmt *sql.Stmt, err error)
- func (dbs *DBs) PrepareContext(ctx context.Context, query string) (db *sqlx.DB, stmt *sql.Stmt, err error)
- func (dbs *DBs) PrepareContextOnSlave(ctx context.Context, query string) (db *sqlx.DB, stmt *sql.Stmt, err error)
- func (dbs *DBs) PrepareNamed(query string) (db *sqlx.DB, stmt *sqlx.NamedStmt, err error)
- func (dbs *DBs) PrepareNamedContext(ctx context.Context, query string) (db *sqlx.DB, stmt *sqlx.NamedStmt, err error)
- func (dbs *DBs) PrepareNamedContextOnSlave(ctx context.Context, query string) (db *sqlx.DB, stmt *sqlx.NamedStmt, err error)
- func (dbs *DBs) PrepareNamedOnSlave(query string) (db *sqlx.DB, stmt *sqlx.NamedStmt, err error)
- func (dbs *DBs) PrepareOnSlave(query string) (db *sqlx.DB, stmt *sql.Stmt, err error)
- func (dbs *DBs) Preparex(query string) (db *sqlx.DB, stmt *sqlx.Stmt, err error)
- func (dbs *DBs) PreparexContext(ctx context.Context, query string) (db *sqlx.DB, stmt *sqlx.Stmt, err error)
- func (dbs *DBs) PreparexContextOnSlave(ctx context.Context, query string) (db *sqlx.DB, stmt *sqlx.Stmt, err error)
- func (dbs *DBs) PreparexOnSlave(query string) (db *sqlx.DB, stmt *sqlx.Stmt, err error)
- func (dbs *DBs) Query(query string, args ...interface{}) (r *sql.Rows, err error)
- func (dbs *DBs) QueryContext(ctx context.Context, query string, args ...interface{}) (r *sql.Rows, err error)
- func (dbs *DBs) QueryContextOnMaster(ctx context.Context, query string, args ...interface{}) (r *sql.Rows, err error)
- func (dbs *DBs) QueryOnMaster(query string, args ...interface{}) (r *sql.Rows, err error)
- func (dbs *DBs) QueryRow(query string, args ...interface{}) (r *sql.Row, err error)
- func (dbs *DBs) QueryRowContext(ctx context.Context, query string, args ...interface{}) (r *sql.Row, err error)
- func (dbs *DBs) QueryRowContextOnMaster(ctx context.Context, query string, args ...interface{}) (r *sql.Row, err error)
- func (dbs *DBs) QueryRowOnMaster(query string, args ...interface{}) (r *sql.Row, err error)
- func (dbs *DBs) QueryRowx(query string, args ...interface{}) (r *sqlx.Row, err error)
- func (dbs *DBs) QueryRowxContext(ctx context.Context, query string, args ...interface{}) (r *sqlx.Row, err error)
- func (dbs *DBs) QueryRowxContextOnMaster(ctx context.Context, query string, args ...interface{}) (r *sqlx.Row, err error)
- func (dbs *DBs) QueryRowxOnMaster(query string, args ...interface{}) (r *sqlx.Row, err error)
- func (dbs *DBs) Queryx(query string, args ...interface{}) (r *sqlx.Rows, err error)
- func (dbs *DBs) QueryxContext(ctx context.Context, query string, args ...interface{}) (r *sqlx.Rows, err error)
- func (dbs *DBs) QueryxContextOnMaster(ctx context.Context, query string, args ...interface{}) (r *sqlx.Rows, err error)
- func (dbs *DBs) QueryxOnMaster(query string, args ...interface{}) (r *sqlx.Rows, err error)
- func (dbs *DBs) Rebind(query string) string
- func (dbs *DBs) Select(dest interface{}, query string, args ...interface{}) (err error)
- func (dbs *DBs) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
- func (dbs *DBs) SelectContextOnMaster(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
- func (dbs *DBs) SelectOnMaster(dest interface{}, query string, args ...interface{}) (err error)
- func (dbs *DBs) SetConnMaxLifetime(d time.Duration)
- func (dbs *DBs) SetHealthCheckPeriod(period uint64)
- func (dbs *DBs) SetMasterConnMaxLifetime(d time.Duration)
- func (dbs *DBs) SetMasterHealthCheckPeriod(period uint64)
- func (dbs *DBs) SetMasterMaxIdleConns(n int)
- func (dbs *DBs) SetMasterMaxOpenConns(n int)
- func (dbs *DBs) SetMaxIdleConns(n int)
- func (dbs *DBs) SetMaxOpenConns(n int)
- func (dbs *DBs) SetSlaveConnMaxLifetime(d time.Duration)
- func (dbs *DBs) SetSlaveHealthCheckPeriod(period uint64)
- func (dbs *DBs) SetSlaveMaxIdleConns(n int)
- func (dbs *DBs) SetSlaveMaxOpenConns(n int)
- func (dbs *DBs) Stats() (stats []sql.DBStats)
- func (dbs *DBs) StatsMaster() (stats []sql.DBStats)
- func (dbs *DBs) StatsSlave() (stats []sql.DBStats)
Constants ¶
const (
// DefaultHealthCheckPeriodInMilli default period in millisecond mssqlx should do a health check of failed database
DefaultHealthCheckPeriodInMilli = 40
)
Variables ¶
var ( // ErrNetwork networking error ErrNetwork = errors.New("Network error/Connection refused") // ErrNoConnection there is no connection to db ErrNoConnection = errors.New("No connection available") // ErrNoConnectionOrWsrep there is no connection to db or Wsrep is not ready ErrNoConnectionOrWsrep = errors.New("No connection available or Wsrep is not ready") )
Functions ¶
This section is empty.
Types ¶
type DBs ¶
type DBs struct {
// contains filtered or unexported fields
}
DBs sqlx wrapper supports querying master-slave database connections for HA and scalability, auto-balancer integrated.
func ConnectMasterSlaves ¶
func ConnectMasterSlaves(driverName string, masterDSNs []string, slaveDSNs []string, args ...interface{}) (*DBs, []error)
ConnectMasterSlaves to master-slave databases, healthchecks will ensure they are working driverName: mysql, postgres, etc. masterDSNs: data source names of Masters. slaveDSNs: data source names of Slaves. args: args[0] = true to indicates galera/wsrep cluster.
func (*DBs) Begin ¶
Begin starts a transaction. The default isolation level is dependent on the driver.
Transaction is bound to one of master connections.
func (*DBs) BeginTx ¶
BeginTx starts a transaction.
The provided context is used until the transaction is committed or rolled back. If the context is canceled, the sql package will roll back the transaction. Tx.Commit will return an error if the context provided to BeginTx is canceled.
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.
Transaction is bound to one of master connections.
func (*DBs) BeginTxx ¶
BeginTxx begins a transaction and returns an *sqlx.Tx instead of an *sql.Tx.
The provided context is used until the transaction is committed or rolled back. If the context is canceled, the sql package will roll back the transaction. Tx.Commit will return an error if the context provided to BeginxContext is canceled.
Transaction is bound to one of master connections.
func (*DBs) Beginx ¶
Beginx begins a transaction and returns an *sqlx.Tx instead of an *sql.Tx.
Transaction is bound to one of master connections.
func (*DBs) Destroy ¶
Destroy closes all database connections, releasing any open resources.
It is rare to Close a DB, as the DB handle is meant to be long-lived and shared between many goroutines.
func (*DBs) DestroyMaster ¶
DestroyMaster closes all master database connections, releasing any open resources.
It is rare to Close a DB, as the DB handle is meant to be long-lived and shared between many goroutines.
func (*DBs) DestroySlave ¶
DestroySlave closes all master database connections, releasing any open resources.
It is rare to Close a DB, as the DB handle is meant to be long-lived and shared between many goroutines.
func (*DBs) DriverName ¶
DriverName returns the driverName passed to the Open function for this DB.
func (*DBs) ExecContext ¶
func (dbs *DBs) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext do exec on masters with context
func (*DBs) ExecContextOnSlave ¶
func (dbs *DBs) ExecContextOnSlave(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContextOnSlave do exec on slaves with context
func (*DBs) ExecOnSlave ¶
ExecOnSlave do exec on slaves.
func (*DBs) Get ¶
Get on slaves. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*DBs) GetAllMasters ¶
GetAllMasters get all master database connections, included failing one.
func (*DBs) GetAllSlaves ¶
GetAllSlaves get all slave database connections, included failing one.
func (*DBs) GetContext ¶
func (dbs *DBs) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
GetContext on slaves. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*DBs) GetContextOnMaster ¶
func (dbs *DBs) GetContextOnMaster(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
GetContextOnMaster on masters. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*DBs) GetOnMaster ¶
GetOnMaster on masters. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.
func (*DBs) MapperFunc ¶
MapperFunc sets a new mapper for this db using the default sqlx struct tag and the provided mapper function.
func (*DBs) MapperFuncMaster ¶
MapperFuncMaster sets a new mapper for this db using the default sqlx struct tag and the provided mapper function.
func (*DBs) MapperFuncSlave ¶
MapperFuncSlave sets a new mapper for this db using the default sqlx struct tag and the provided mapper function.
func (*DBs) MustBegin ¶
MustBegin starts a transaction, and panics on error. Transaction is bound to one of master connections.
func (*DBs) MustBeginTx ¶
MustBeginTx starts a transaction, and panics on error. Returns an *sqlx.Tx instead of an *sql.Tx.
The provided context is used until the transaction is committed or rolled back. If the context is canceled, the sql package will roll back the transaction. Tx.Commit will return an error if the context provided to MustBeginContext is canceled.
Transaction is bound to one of master connections.
func (*DBs) MustBeginx ¶
MustBeginx starts a transaction, and panics on error. Returns an *sqlx.Tx instead of an *sql.Tx. Transaction is bound to one of master connections.
func (*DBs) MustExecContext ¶
MustExecContext do exec on masters and panic on error
func (*DBs) MustExecContextOnSlave ¶
func (dbs *DBs) MustExecContextOnSlave(ctx context.Context, query string, args ...interface{}) sql.Result
MustExecContextOnSlave do exec on slave only and panic on error
func (*DBs) MustExecOnSlave ¶
MustExecOnSlave do exec on slave only and panic on error
func (*DBs) NamedExec ¶
NamedExec do named exec. Any named placeholder parameters are replaced with fields from arg.
func (*DBs) NamedExecContext ¶
func (dbs *DBs) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
NamedExecContext do named exec with context. Any named placeholder parameters are replaced with fields from arg.
func (*DBs) NamedExecContextOnSlave ¶
func (dbs *DBs) NamedExecContextOnSlave(ctx context.Context, query string, arg interface{}) (sql.Result, error)
NamedExecContextOnSlave do named exec with context on slave. Any named placeholder parameters are replaced with fields from arg.
func (*DBs) NamedExecOnSlave ¶
NamedExecOnSlave do named exec on slave. Any named placeholder parameters are replaced with fields from arg.
func (*DBs) NamedQuery ¶
NamedQuery do named query. Any named placeholder parameters are replaced with fields from arg.
func (*DBs) NamedQueryContext ¶
func (dbs *DBs) NamedQueryContext(ctx context.Context, query string, arg interface{}) (*sqlx.Rows, error)
NamedQueryContext do named query with context. Any named placeholder parameters are replaced with fields from arg.
func (*DBs) NamedQueryContextOnMaster ¶
func (dbs *DBs) NamedQueryContextOnMaster(ctx context.Context, query string, arg interface{}) (*sqlx.Rows, error)
NamedQueryContextOnMaster do named query with context on master. Any named placeholder parameters are replaced with fields from arg.
func (*DBs) NamedQueryOnMaster ¶
NamedQueryOnMaster do named query on master. Any named placeholder parameters are replaced with fields from arg.
func (*DBs) PingMaster ¶
PingMaster all master database connections
func (*DBs) Prepare ¶
Prepare creates a prepared statement for later queries or executions on masters. 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 (*DBs) PrepareContext ¶
func (dbs *DBs) PrepareContext(ctx context.Context, query string) (db *sqlx.DB, stmt *sql.Stmt, err error)
PrepareContext creates a prepared statement for later queries or executions on masters. 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 (*DBs) PrepareContextOnSlave ¶
func (dbs *DBs) PrepareContextOnSlave(ctx context.Context, query string) (db *sqlx.DB, stmt *sql.Stmt, err error)
PrepareContextOnSlave creates a prepared statement for later queries or executions on slaves. 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 (*DBs) PrepareNamed ¶
PrepareNamed returns an sqlx.NamedStmt on masters
func (*DBs) PrepareNamedContext ¶
func (dbs *DBs) PrepareNamedContext(ctx context.Context, query string) (db *sqlx.DB, stmt *sqlx.NamedStmt, err error)
PrepareNamedContext returns an sqlx.NamedStmt on masters
func (*DBs) PrepareNamedContextOnSlave ¶
func (dbs *DBs) PrepareNamedContextOnSlave(ctx context.Context, query string) (db *sqlx.DB, stmt *sqlx.NamedStmt, err error)
PrepareNamedContextOnSlave returns an sqlx.NamedStmt on slaves
func (*DBs) PrepareNamedOnSlave ¶
PrepareNamedOnSlave returns an sqlx.NamedStmt on slaves
func (*DBs) PrepareOnSlave ¶
PrepareOnSlave creates a prepared statement for later queries or executions on slaves. 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 (*DBs) Preparex ¶
Preparex creates a prepared statement for later queries or executions on masters. But return sqlx.Stmt instead of sql.Stmt. 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 (*DBs) PreparexContext ¶
func (dbs *DBs) PreparexContext(ctx context.Context, query string) (db *sqlx.DB, stmt *sqlx.Stmt, err error)
PreparexContext creates a prepared statement for later queries or executions on masters. But return sqlx.Stmt instead of sql.Stmt. 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 (*DBs) PreparexContextOnSlave ¶
func (dbs *DBs) PreparexContextOnSlave(ctx context.Context, query string) (db *sqlx.DB, stmt *sqlx.Stmt, err error)
PreparexContextOnSlave creates a prepared statement for later queries or executions on slaves. But return sqlx.Stmt instead of sql.Stmt. 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 (*DBs) PreparexOnSlave ¶
PreparexOnSlave creates a prepared statement for later queries or executions on slaves. But return sqlx.Stmt instead of sql.Stmt. 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 (*DBs) Query ¶
Query executes a query on slaves that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DBs) QueryContext ¶
func (dbs *DBs) QueryContext(ctx context.Context, query string, args ...interface{}) (r *sql.Rows, err error)
QueryContext executes a query on slaves that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DBs) QueryContextOnMaster ¶
func (dbs *DBs) QueryContextOnMaster(ctx context.Context, query string, args ...interface{}) (r *sql.Rows, err error)
QueryContextOnMaster executes a query on masters that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DBs) QueryOnMaster ¶
QueryOnMaster executes a query on masters that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DBs) QueryRow ¶
QueryRow executes a query on slaves 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.
func (*DBs) QueryRowContext ¶
func (dbs *DBs) QueryRowContext(ctx context.Context, query string, args ...interface{}) (r *sql.Row, err error)
QueryRowContext executes a query on slaves 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.
func (*DBs) QueryRowContextOnMaster ¶
func (dbs *DBs) QueryRowContextOnMaster(ctx context.Context, query string, args ...interface{}) (r *sql.Row, err error)
QueryRowContextOnMaster executes a query on masters 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.
func (*DBs) QueryRowOnMaster ¶
QueryRowOnMaster executes a query on masters 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.
func (*DBs) QueryRowx ¶
QueryRowx executes a query on slaves that is expected to return at most one row. But return sqlx.Row instead of sql.Row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called.
func (*DBs) QueryRowxContext ¶
func (dbs *DBs) QueryRowxContext(ctx context.Context, query string, args ...interface{}) (r *sqlx.Row, err error)
QueryRowxContext executes a query on slaves 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.
func (*DBs) QueryRowxContextOnMaster ¶
func (dbs *DBs) QueryRowxContextOnMaster(ctx context.Context, query string, args ...interface{}) (r *sqlx.Row, err error)
QueryRowxContextOnMaster executes a query on masters 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.
func (*DBs) QueryRowxOnMaster ¶
QueryRowxOnMaster executes a query on masters 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.
func (*DBs) Queryx ¶
Queryx executes a query on slaves that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DBs) QueryxContext ¶
func (dbs *DBs) QueryxContext(ctx context.Context, query string, args ...interface{}) (r *sqlx.Rows, err error)
QueryxContext executes a query on slaves that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DBs) QueryxContextOnMaster ¶
func (dbs *DBs) QueryxContextOnMaster(ctx context.Context, query string, args ...interface{}) (r *sqlx.Rows, err error)
QueryxContextOnMaster executes a query on masters that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DBs) QueryxOnMaster ¶
QueryxOnMaster executes a query on masters that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DBs) Select ¶
Select do select on slaves. Any placeholder parameters are replaced with supplied args.
func (*DBs) SelectContext ¶
func (dbs *DBs) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
SelectContext do select on slaves with context. Any placeholder parameters are replaced with supplied args.
func (*DBs) SelectContextOnMaster ¶
func (dbs *DBs) SelectContextOnMaster(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
SelectContextOnMaster do select on masters with context. Any placeholder parameters are replaced with supplied args.
func (*DBs) SelectOnMaster ¶
SelectOnMaster do select on masters. Any placeholder parameters are replaced with supplied args.
func (*DBs) SetConnMaxLifetime ¶
SetConnMaxLifetime sets the maximum amount of time a master-slave connection may be reused.
Expired connections may be closed lazily before reuse.
If d <= 0, connections are reused forever.
func (*DBs) SetHealthCheckPeriod ¶
SetHealthCheckPeriod sets the period (in millisecond) for checking health of failed nodes for automatic recovery.
Default is 500
func (*DBs) SetMasterConnMaxLifetime ¶
SetMasterConnMaxLifetime sets the maximum amount of time a master connection may be reused.
Expired connections may be closed lazily before reuse.
If d <= 0, connections are reused forever.
func (*DBs) SetMasterHealthCheckPeriod ¶
SetMasterHealthCheckPeriod sets the period (in millisecond) for checking health of failed master nodes for automatic recovery.
Default is 500
func (*DBs) SetMasterMaxIdleConns ¶
SetMasterMaxIdleConns sets the maximum number of connections in the idle connection pool for masters.
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 (*DBs) SetMasterMaxOpenConns ¶
SetMasterMaxOpenConns sets the maximum number of open connections to the master databases.
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).
func (*DBs) SetMaxIdleConns ¶
SetMaxIdleConns sets the maximum number of connections in the idle connection pool for all masters-slaves.
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 (*DBs) SetMaxOpenConns ¶
SetMaxOpenConns sets the maximum number of open connections to all master-slave databases.
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).
func (*DBs) SetSlaveConnMaxLifetime ¶
SetSlaveConnMaxLifetime sets the maximum amount of time a slave connection may be reused.
Expired connections may be closed lazily before reuse.
If d <= 0, connections are reused forever.
func (*DBs) SetSlaveHealthCheckPeriod ¶
SetSlaveHealthCheckPeriod sets the period (in millisecond) for checking health of failed slave nodes for automatic recovery.
Default is 500
func (*DBs) SetSlaveMaxIdleConns ¶
SetSlaveMaxIdleConns sets the maximum number of connections in the idle connection pool for slaves.
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 (*DBs) SetSlaveMaxOpenConns ¶
SetSlaveMaxOpenConns sets the maximum number of open connections to the slave databases.
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).
func (*DBs) StatsMaster ¶
StatsMaster returns master database statistics.
func (*DBs) StatsSlave ¶
StatsSlave returns slave database statistics.