cluster

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFromConfigs

func NewFromConfigs(config []*pgxpool.Config, opts ...Option) (*cluster, error)

NewFromConfigs concurrently opens each underlying physical db. first being used as the primary and the rest as replica.

func Open

func Open(dsn []string, opts ...Option) (*cluster, error)

Open concurrently opens each underlying physical db. DSN must be valid according to https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING first being used as the primary and the rest as replica.

Types

type Conn

type Conn interface {
	Select(ctx context.Context, dst interface{}, sql string, args ...interface{}) error
	Get(ctx context.Context, dst interface{}, sql string, args ...interface{}) error
	Exec(ctx context.Context, sql string, args ...interface{}) (int64, error)
	Tx(ctx context.Context, f func(n conn.Querier) error, opts ...conn.TxOption) error
	Primary() conn.Querier
	Replica() conn.Querier
	Ping(context.Context) error
	Close() error
}

Conn is a logical database with multiple underlying physical databases forming a single primary multiple replica topology. Reads(Get, Select) and writes(Exec, Tx) are automatically directed to the correct physical db.

type ConnPicker

type ConnPicker func(db Conn, sql string) conn.Querier

type Option

type Option func(*Options)

Option func.

func WithConnPicker

func WithConnPicker(picker ConnPicker) Option

WithConnPicker sets connection picker for Select and Get

func WithScanAPI

func WithScanAPI(api *pgxscan.API) Option

WithConnPicker sets custom pgxscan api

type Options

type Options struct {
	Picker  ConnPicker
	ScanAPI *pgxscan.API
}

Options for cluster.

Jump to

Keyboard shortcuts

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