Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DBConfig ¶
type DBConfig struct {
Driver DBEngine `json:"driver" yaml:"driver"`
MasterDSN string `json:"master" yaml:"master"`
SlaveDSN string `json:"slave" yaml:"slave"`
MaxOpenConnections int `json:"max_open_conns" yaml:"max_open_conns"`
MaxIdleConnections int `json:"max_idle_conns" yaml:"max_idle_conns"`
ConnectionMaxLifetime time.Duration `json:"conn_max_lifetime" yaml:"conn_max_lifetime"`
Retry int `json:"retry" yaml:"retry"`
}
type Master ¶
type Master interface {
Exec(query string, args ...interface{}) (sql.Result, error)
// ExecContext use master database to exec query
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
// Begin transaction on master DB
Begin() (*sql.Tx, error)
// BeginTx begins transaction on master DB
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
// Rebind a query from the default bindtype (QUESTION) to the target bindtype.
Rebind(sql string) string
// NamedExec do named exec on master DB
NamedExec(query string, arg interface{}) (sql.Result, error)
// NamedExecContext do named exec on master DB
NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
// BindNamed do BindNamed on master DB
BindNamed(query string, arg interface{}) (string, []interface{}, error)
}
Master defines operation that will be executed to master DB
type Slave ¶
type Slave interface {
// Get from slave database
Get(dest interface{}, query string, args ...interface{}) error
// Select from slave database
Select(dest interface{}, query string, args ...interface{}) error
// Query from slave database
Query(query string, args ...interface{}) (*sql.Rows, error)
// QueryRow executes QueryRow against slave DB
QueryRow(query string, args ...interface{}) *sql.Row
// NamedQuery do named query on slave DB
NamedQuery(query string, arg interface{}) (*sqlx.Rows, error)
// GetContext from sql database
GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
// SelectContext from sql database
SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
// QueryContext from sql database
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
// QueryRowContext from sql database
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
// QueryxContext queries the database and returns an *sqlx.Rows. Any placeholder parameters are replaced with supplied args.
QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
// QueryRowxContext queries the database and returns an *sqlx.Row. Any placeholder parameters are replaced with supplied args.
QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row
// NamedQueryContext do named query on slave DB
NamedQueryContext(ctx context.Context, query string, arg interface{}) (*sqlx.Rows, error)
}
Slave defines operation that will be executed to slave DB
Click to show internal directories.
Click to hide internal directories.