dbx

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Scan

func Scan[T any](rows Rows, pointers func(*T) []interface{}) ([]T, error)

Types

type ConnOpener

type ConnOpener[T any] func(ctx context.Context, driverName string, dsn string) (T, error)

type DB

type DB[T any] struct {
	Cluster *cluster.Cluster[T]

	NodeWaitTimeout time.Duration

	WriteToNode  cluster.NodeStateCriteria // This is used, when we can clearly guess, that query is a write query (for example, Exec())
	ReadFromNode cluster.NodeStateCriteria // This is used, when we can clearly guess, that query is a read query (for example, Query())
	DefaultNode  cluster.NodeStateCriteria // This is used, when we can not figure out, what type of request is formed (like Prepare())

	Ctx context.Context
	// contains filtered or unexported fields
}

func NewDB

func NewDB[T any](driverName string, dsns []string,
	connOpener ConnOpener[T],
	connCloser cluster.ConnCloser[T],
	nodeChecker cluster.NodeChecker[T],
	options ...Option[T]) (*DB[T], error)

func (*DB[T]) Close

func (db *DB[T]) Close()

Close closes all nodes in cluster.

func (*DB[T]) WaitForConn

func (db *DB[T]) WaitForConn(ctx context.Context, criteria cluster.NodeStateCriteria) (T, error)

func (*DB[T]) WaitForDefaultConn

func (db *DB[T]) WaitForDefaultConn(ctx context.Context) (T, error)

func (*DB[T]) WaitForReadFromConn

func (db *DB[T]) WaitForReadFromConn(ctx context.Context) (T, error)

func (*DB[T]) WaitForWriteToConn

func (db *DB[T]) WaitForWriteToConn(ctx context.Context) (T, error)

type DBxer

type DBxer[TConn any, TTx any, TTxOptions any] interface {
	DoTx(f func(db DBxer[TConn, TTx, TTxOptions]) error, opts TTxOptions) error
	DoTxContext(
		ctx context.Context,
		f func(ctx context.Context, db DBxer[TConn, TTx, TTxOptions]) error,
		opts TTxOptions) error
	Tx() (TTx, error)
	WaitForConn(ctx context.Context, criteria cluster.NodeStateCriteria) (TConn, error)
	WaitForWriteToConn(ctx context.Context) (TConn, error)
	WaitForReadFromConn(ctx context.Context) (TConn, error)
	WaitForDefaultConn(ctx context.Context) (TConn, error)
}

type Option

type Option[T any] func(*DB[T])

func WithClusterOptions

func WithClusterOptions[T any](options ...cluster.ClusterOption[T]) Option[T]

func WithCtx

func WithCtx[T any](ctx context.Context) Option[T]

func WithDefaultNode

func WithDefaultNode[T any](criteria cluster.NodeStateCriteria) Option[T]

func WithNodeWaitTimeout

func WithNodeWaitTimeout[T any](timeout time.Duration) Option[T]

func WithReadFromNode

func WithReadFromNode[T any](criteria cluster.NodeStateCriteria) Option[T]

func WithWriteToNode

func WithWriteToNode[T any](criteria cluster.NodeStateCriteria) Option[T]

type Row

type Row interface {
	Err() error
	Scan(dest ...any) error
}

type Rows

type Rows interface {
	Row
	Next() bool
}

Directories

Path Synopsis
checkers
sql
closers
sql
impl
sql

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL