pgds

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2025 License: MIT Imports: 7 Imported by: 11

Documentation

Overview

pgds package implements postgresql data storage based on pgx driver. It supports schema with one primary and several secondaty servers. Primary server is retrieved by GetPrimary() method. Primary server is used for write queries (INSER/UPDATE/DELETE) The list used secondary server is returned by GetSecondary() function. Secondary servers are read-only, used for SELECT queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Db

type Db struct {
	Pool *pgxpool.Pool
	// contains filtered or unexported fields
}

Db holds db instances.

func (*Db) Connect

func (d *Db) Connect() error

Connect opens connection with data base.

func (*Db) GetRefCount

func (d *Db) GetRefCount() int

GetRefCount returns active db instancie counter.

type OnDbNotificationProto

type OnDbNotificationProto = func(*pgconn.PgConn, *pgconn.Notification)

OnDbNotificationProto pg notification callback function.

type PgProvider

type PgProvider struct {
	Primary     *Db
	Secondaries map[ServerID]*Db
}

PgProvider holds one primary and array of secondary instances.

func (*PgProvider) GetPrimary

func (p *PgProvider) GetPrimary() (*pgxpool.Conn, ServerID, error)

GetPrimary returns primary connection with its ID. ID is necessary for releasing.

func (*PgProvider) GetSecondary

func (p *PgProvider) GetSecondary(srvLsn string) (*pgxpool.Conn, ServerID, error)

GetSecondary looks for an avalable secondary with less ref count. srvLsn is a pg replication log position. If empty the list busy server will be returned. Otherwise server which position is higher then given lsn. If nothing found returns primary.

func (*PgProvider) InitProvider

func (p *PgProvider) InitProvider(provParams []interface{}) error

InitProvider initializes provider. Expects parameters:

primaryConnStr string containing connection to data base.
onDbNotification of type OnDbNotificationProto. Callback function to be used for database notifications.
secondaries map[string]string of IDs with connection strings. Key is the server ID and value is a connection string.

func (*PgProvider) Release

func (p *PgProvider) Release(poolConn *pgxpool.Conn, id ServerID)

Release releases database connection by its ID (primary or secondary).

func (*PgProvider) ReleasePrimary

func (p *PgProvider) ReleasePrimary(poolConn *pgxpool.Conn)

func (*PgProvider) ReleaseSecondary

func (p *PgProvider) ReleaseSecondary(poolConn *pgxpool.Conn, connID ServerID)

ReleaseSecondary releases secondary connection by its ID. Deprecated: use common Release()

type ServerID

type ServerID string
const PRIMARY_ID ServerID = "primary" //primary server ID

Jump to

Keyboard shortcuts

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