Documentation ¶
Index ¶
- Constants
- Variables
- func IsDeadlock(err error) bool
- func IsWsrepNotReady(err error) bool
- type DBs
- func (dbs *DBs) Begin() (*Tx, error)
- func (dbs *DBs) BeginTx(ctx context.Context, opts *sql.TxOptions) (res *Tx, err error)
- func (dbs *DBs) BeginTxx(ctx context.Context, opts *sql.TxOptions) (res *Txx, err error)
- func (dbs *DBs) Beginx() (res *Txx, 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() *Tx
- func (dbs *DBs) MustBeginTx(ctx context.Context, opts *sql.TxOptions) *Txx
- func (dbs *DBs) MustBeginx() *Txx
- 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{}) *sql.Row
- func (dbs *DBs) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (dbs *DBs) QueryRowContextOnMaster(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (dbs *DBs) QueryRowOnMaster(query string, args ...interface{}) *sql.Row
- func (dbs *DBs) QueryRowx(query string, args ...interface{}) *sqlx.Row
- func (dbs *DBs) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row
- func (dbs *DBs) QueryRowxContextOnMaster(ctx context.Context, query string, args ...interface{}) *sqlx.Row
- func (dbs *DBs) QueryRowxOnMaster(query string, args ...interface{}) *sqlx.Row
- 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)
- type Instantiate
- type Option
- type ReadQuerySource
- type Stmt
- func (s *Stmt) Exec(args ...interface{}) (sql.Result, error)
- func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) (result sql.Result, err error)
- func (s *Stmt) Query(args ...interface{}) (*sql.Rows, error)
- func (s *Stmt) QueryContext(ctx context.Context, args ...interface{}) (result *sql.Rows, err error)
- type Stmtx
- func (s *Stmtx) Exec(args ...interface{}) (sql.Result, error)
- func (s *Stmtx) ExecContext(ctx context.Context, args ...interface{}) (result sql.Result, err error)
- func (s *Stmtx) Query(args ...interface{}) (*sql.Rows, error)
- func (s *Stmtx) QueryContext(ctx context.Context, args ...interface{}) (result *sql.Rows, err error)
- func (s *Stmtx) Queryx(args ...interface{}) (*sqlx.Rows, error)
- func (s *Stmtx) QueryxContext(ctx context.Context, args ...interface{}) (result *sqlx.Rows, err error)
- type Tx
- func (t *Tx) Commit() (err error)
- func (t *Tx) Exec(query string, args ...interface{}) (result sql.Result, err error)
- func (t *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (result sql.Result, err error)
- func (t *Tx) Prepare(query string) (*Stmt, error)
- func (t *Tx) PrepareContext(ctx context.Context, query string) (result *Stmt, err error)
- func (t *Tx) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (t *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (result *sql.Rows, err error)
- type Txx
- func (t *Txx) Commit() (err error)
- func (t *Txx) Exec(query string, args ...interface{}) (result sql.Result, err error)
- func (t *Txx) ExecContext(ctx context.Context, query string, args ...interface{}) (result sql.Result, err error)
- func (t *Txx) Prepare(query string) (*Stmt, error)
- func (t *Txx) PrepareContext(ctx context.Context, query string) (result *Stmt, err error)
- func (t *Txx) Preparex(query string) (*Stmtx, error)
- func (t *Txx) PreparexContext(ctx context.Context, query string) (result *Stmtx, err error)
- func (t *Txx) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (t *Txx) QueryContext(ctx context.Context, query string, args ...interface{}) (result *sql.Rows, err error)
- func (t *Txx) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
- func (t *Txx) QueryxContext(ctx context.Context, query string, args ...interface{}) (result *sqlx.Rows, err error)
Constants ¶
const (
// DefaultHealthCheckPeriodInMilli default period in millisecond mssqlx should do a health check of failed database
DefaultHealthCheckPeriodInMilli = 40
)
Variables ¶
var ( // 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 ¶
func IsDeadlock ¶ added in v1.1.0
IsDeadlock ERROR 1213: Deadlock found when trying to get lock
func IsWsrepNotReady ¶ added in v1.1.0
IsWsrepNotReady ERROR 1047: WSREP has not yet prepared node for application use
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, options ...Option) (*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 ReadQuerySourceSlaves.
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.
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.
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.
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.
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 ¶
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{}) *sql.Row
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 ¶
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{}) *sqlx.Row
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.
type Instantiate ¶ added in v1.1.2
Instantiate db.
type Option ¶ added in v1.0.8
type Option func(*clusterOptions)
Option setter.
func WithDBInstantiate ¶ added in v1.1.2
func WithDBInstantiate(f Instantiate) Option
WithDBInstantiate overwrite instantiate for db conn.
func WithReadQuerySource ¶ added in v1.0.8
func WithReadQuerySource(source ReadQuerySource) Option
WithReadQuerySource sets default sources for read-queries.
type ReadQuerySource ¶ added in v1.0.8
type ReadQuerySource int
ReadQuerySource enums.
const ( // ReadQuerySourceSlaves setting indicates: read-queries will be distributed only among slaves. // // Note: there is no option for Master. One could use functions like `QueryMaster`, etc // to query from masters only. ReadQuerySourceSlaves ReadQuerySource = iota // ReadQuerySourceAll setting indicates: read-queries will be distributed among both masters and slaves. // // Note: this is default setting. ReadQuerySourceAll )
type Stmt ¶ added in v1.1.0
Stmt wraps over sql.Stmt
func (*Stmt) Exec ¶ added in v1.1.0
Exec executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
func (*Stmt) ExecContext ¶ added in v1.1.0
ExecContext executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
type Stmtx ¶ added in v1.1.0
Stmtx wraps over sqlx.Stmt
func (*Stmtx) Exec ¶ added in v1.1.0
Exec executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
func (*Stmtx) ExecContext ¶ added in v1.1.0
func (s *Stmtx) ExecContext(ctx context.Context, args ...interface{}) (result sql.Result, err error)
ExecContext executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
func (*Stmtx) Query ¶ added in v1.1.0
Query executes a prepared query statement with the given arguments and returns the query results as a *Rows.
func (*Stmtx) QueryContext ¶ added in v1.1.0
func (s *Stmtx) QueryContext(ctx context.Context, args ...interface{}) (result *sql.Rows, err error)
QueryContext executes a prepared query statement with the given arguments and returns the query results as a *Rows.
type Tx ¶ added in v1.1.0
Tx wraps over sql.Tx
func (*Tx) Exec ¶ added in v1.1.0
Exec executes a query that doesn't return rows. For example: an INSERT and UPDATE.
func (*Tx) ExecContext ¶ added in v1.1.0
func (t *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (result sql.Result, err error)
ExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE.
func (*Tx) Prepare ¶ added in v1.1.0
Prepare creates a prepared statement for use within a transaction.
The returned statement operates within the transaction and will be closed when the transaction has been committed or rolled back.
func (*Tx) PrepareContext ¶ added in v1.1.0
PrepareContext creates a prepared statement for use within a transaction.
The returned statement operates within the transaction and will be closed when the transaction has been committed or rolled back.
The provided context will be used for the preparation of the context, not for the execution of the returned statement. The returned statement will run in the transaction context.
type Txx ¶ added in v1.1.0
Txx wraps over sqlx.Tx
func (*Txx) Exec ¶ added in v1.1.0
Exec executes a query that doesn't return rows. For example: an INSERT and UPDATE.
func (*Txx) ExecContext ¶ added in v1.1.0
func (t *Txx) ExecContext(ctx context.Context, query string, args ...interface{}) (result sql.Result, err error)
ExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE.
func (*Txx) Prepare ¶ added in v1.1.0
Prepare creates a prepared statement for use within a transaction.
The returned statement operates within the transaction and will be closed when the transaction has been committed or rolled back.
func (*Txx) PrepareContext ¶ added in v1.1.0
PrepareContext creates a prepared statement for use within a transaction.
The returned statement operates within the transaction and will be closed when the transaction has been committed or rolled back.
The provided context will be used for the preparation of the context, not for the execution of the returned statement. The returned statement will run in the transaction context.
func (*Txx) Preparex ¶ added in v1.1.0
Preparex creates a prepared statement for use within a transaction.
The returned statement operates within the transaction and will be closed when the transaction has been committed or rolled back.
func (*Txx) PreparexContext ¶ added in v1.1.0
PreparexContext creates a prepared statement for use within a transaction.
The returned statement operates within the transaction and will be closed when the transaction has been committed or rolled back.
The provided context will be used for the preparation of the context, not for the execution of the returned statement. The returned statement will run in the transaction context.
func (*Txx) QueryContext ¶ added in v1.1.0
func (t *Txx) QueryContext(ctx context.Context, query string, args ...interface{}) (result *sql.Rows, err error)
QueryContext executes a query that returns rows, typically a SELECT.