Documentation ¶
Index ¶
- Constants
- func Query[T any](db *DB, query string, pointers func(*T) []interface{}, args ...any) ([]T, error)
- func QueryContext[T any](ctx context.Context, db *DB, query string, pointers func(*T) []interface{}, ...) ([]T, error)
- type DB
- func (db *DB) DoTx(f func(db dbx.DBxer[*sql.DB, *sql.Tx, *sql.TxOptions]) error, ...) error
- func (db *DB) DoTxContext(ctx context.Context, ...) error
- func (db *DB) Exec(query string, args ...any) (sql.Result, error)
- func (db *DB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (db *DB) Prepare(query string) (*sql.Stmt, error)
- func (db *DB) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (db *DB) Query(query string, args ...any) (*sql.Rows, error)
- func (db *DB) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (db *DB) QueryRow(query string, args ...any) dbx.Row
- func (db *DB) QueryRowContext(ctx context.Context, query string, args ...any) dbx.Row
- func (db *DB) Tx() (*sql.Tx, error)
- func (db *DB) WithCtx(ctx context.Context) *DB
- func (db *DB) WithDefaultNodeStrategy(strategy dbx.GetNodeStragegy) *DB
- func (db *DB) WithNodeWaitTimeout(timeout time.Duration) *DB
- func (db *DB) WithReadFromNodeStrategy(strategy dbx.GetNodeStragegy) *DB
- func (db *DB) WithWriteToNodeStrategy(strategy dbx.GetNodeStragegy) *DB
- type DBOpener
- type ErrRow
- type Option
Constants ¶
View Source
const DefaultPingTimeout = 15 * time.Second
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DB ¶
func NewDB ¶
func NewDB(driverName string, dsns []string, checker cluster.NodeChecker[*sql.DB], options ...Option) (*DB, error)
NewDB returns an instance of *DB.
func (*DB) DoTx ¶
func (db *DB) DoTx(f func(db dbx.DBxer[*sql.DB, *sql.Tx, *sql.TxOptions]) error, opts *sql.TxOptions) error
DoTx executes passed function in transaction.
func (*DB) DoTxContext ¶
func (db *DB) DoTxContext( ctx context.Context, f func(ctx context.Context, db dbx.DBxer[*sql.DB, *sql.Tx, *sql.TxOptions]) error, opts *sql.TxOptions) error
DoTxContext executes passed function in transaction.
func (*DB) ExecContext ¶
ExecContext executes query with context.
func (*DB) PrepareContext ¶
PrepareContext prepares query with context.
func (*DB) QueryContext ¶
QueryContext queries underlying cluster with context.
func (*DB) QueryRowContext ¶
QueryRowContext queries row from underlying cluster with context.
func (*DB) WithDefaultNodeStrategy ¶ added in v0.0.3
func (db *DB) WithDefaultNodeStrategy(strategy dbx.GetNodeStragegy) *DB
func (*DB) WithNodeWaitTimeout ¶ added in v0.0.3
func (*DB) WithReadFromNodeStrategy ¶ added in v0.0.3
func (db *DB) WithReadFromNodeStrategy(strategy dbx.GetNodeStragegy) *DB
func (*DB) WithWriteToNodeStrategy ¶ added in v0.0.3
func (db *DB) WithWriteToNodeStrategy(strategy dbx.GetNodeStragegy) *DB
type DBOpener ¶
var DefaultDBOpener DBOpener = func(ctx context.Context, driverName, dsn string) (*sql.DB, error) { db, err := sql.Open(driverName, dsn) if err != nil { return nil, errx.Wrap("open db", err) } pingCtx, cancel := context.WithTimeout(context.Background(), DefaultPingTimeout) defer cancel() if err := db.PingContext(pingCtx); err != nil { return nil, errx.Wrap("ping db", err) } return db, nil }
Click to show internal directories.
Click to hide internal directories.