Documentation
¶
Index ¶
- type Cluster
- func (conn *Cluster) Close() error
- func (conn *Cluster) Exec(ctx context.Context, sql string, args ...any) (int64, error)
- func (conn *Cluster) Get(ctx context.Context, dst any, sql string, args ...any) error
- func (conn *Cluster) Ping(ctx context.Context) error
- func (conn *Cluster) Primary() conn.Querier
- func (conn *Cluster) Replica() conn.Querier
- func (conn *Cluster) ScanAPI() *pgxscan.API
- func (conn *Cluster) Select(ctx context.Context, dst any, sql string, args ...any) error
- func (conn *Cluster) Tx(ctx context.Context, f func(n conn.Querier) error, opts ...conn.TxOption) error
- type Conn
- type ConnPicker
- type Option
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
func NewFromConfigs ¶
NewFromConfigs concurrently opens each underlying physical db. first being used as the primary and the rest as replica.
func Open ¶
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.
func (*Cluster) Close ¶
Close closes all physical databases concurrently, releasing any open resources.
func (*Cluster) Exec ¶
Exec executes a query on primary without returning any rows and return affected rows.
func (*Cluster) Get ¶
Get retrieve one row. Get uses a replica by default. See Querier.Get for details.
func (*Cluster) Ping ¶
Ping verifies if a connection to each physical database is still alive, establishing a connection if necessary.
type Conn ¶
type Conn interface {
Select(ctx context.Context, dst any, sql string, args ...any) error
Get(ctx context.Context, dst any, sql string, args ...any) error
Exec(ctx context.Context, sql string, args ...any) (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 Option ¶
type Option func(*Options)
Option func.
func WithConnPicker ¶
func WithConnPicker(picker ConnPicker) Option
WithConnPicker sets connection picker for Select and Get.