dbx

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDatabase added in v0.0.10

func GetDatabase(dsn string) (string, error)

func GetHost added in v0.0.10

func GetHost(dsn string) (string, error)

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

	WriteToNodeStrategy  GetNodeStragegy // This is used, when we can clearly guess, that query is a write query (for example, Exec())
	ReadFromNodeStrategy GetNodeStragegy // This is used, when we can clearly guess, that query is a read query (for example, Query())
	DefaultNodeStrategy  GetNodeStragegy // 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]) Copy added in v0.0.7

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

func (*DB[T]) GetConn added in v0.0.3

func (db *DB[T]) GetConn(ctx context.Context, strategy GetNodeStragegy) (T, error)

func (*DB[T]) GetDefaultConn added in v0.0.3

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

func (*DB[T]) GetReadFromConn added in v0.0.3

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

func (*DB[T]) GetWriteToConn added in v0.0.3

func (db *DB[T]) GetWriteToConn(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)
	GetConn(ctx context.Context, strategy GetNodeStragegy) (TConn, error)
	GetWriteToConn(ctx context.Context) (TConn, error)
	GetReadFromConn(ctx context.Context) (TConn, error)
	GetDefaultConn(ctx context.Context) (TConn, error)
	Close()
}

type GetNodeStragegy added in v0.0.3

type GetNodeStragegy struct {
	Criteria cluster.NodeStateCriteria
	Wait     bool
}

func NoWait added in v0.0.3

func NoWait(criteria cluster.NodeStateCriteria) GetNodeStragegy

func NoWaitAlive added in v0.0.3

func NoWaitAlive() GetNodeStragegy

func NoWaitPrimary added in v0.0.3

func NoWaitPrimary() GetNodeStragegy

func NoWaitPrimaryPreferred added in v0.0.3

func NoWaitPrimaryPreferred() GetNodeStragegy

func NoWaitStandby added in v0.0.3

func NoWaitStandby() GetNodeStragegy

func NoWaitStandbyPreferred added in v0.0.3

func NoWaitStandbyPreferred() GetNodeStragegy

func WaitForAlive added in v0.0.3

func WaitForAlive() GetNodeStragegy

func WaitForPrimary added in v0.0.3

func WaitForPrimary() GetNodeStragegy

func WaitForPrimaryPreferred added in v0.0.3

func WaitForPrimaryPreferred() GetNodeStragegy

func WaitForStandby added in v0.0.3

func WaitForStandby() GetNodeStragegy

func WaitForStandbyPreferred added in v0.0.3

func WaitForStandbyPreferred() GetNodeStragegy

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 WithDefaultNodeStrategy added in v0.0.3

func WithDefaultNodeStrategy[T any](strategy GetNodeStragegy) Option[T]

func WithNodeWaitTimeout

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

func WithReadFromNodeStrategy added in v0.0.3

func WithReadFromNodeStrategy[T any](strategy GetNodeStragegy) Option[T]

func WithWriteToNodeStrategy added in v0.0.3

func WithWriteToNodeStrategy[T any](strategy GetNodeStragegy) 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