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 ¶
- type Db
- type OnDbNotificationProto
- type PgProvider
- func (p *PgProvider) GetPrimary() (*pgxpool.Conn, ServerID, error)
- func (p *PgProvider) GetSecondary(srvLsn string) (*pgxpool.Conn, ServerID, error)
- func (p *PgProvider) InitProvider(provParams []interface{}) error
- func (p *PgProvider) Release(poolConn *pgxpool.Conn, id ServerID)
- func (p *PgProvider) ReleasePrimary(poolConn *pgxpool.Conn)
- func (p *PgProvider) ReleaseSecondary(poolConn *pgxpool.Conn, connID ServerID)
- type ServerID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Db ¶
Db holds db instances.
func (*Db) GetRefCount ¶
GetRefCount returns active db instancie counter.
type OnDbNotificationProto ¶
type OnDbNotificationProto = func(*pgconn.PgConn, *pgconn.Notification)
OnDbNotificationProto pg notification callback function.
type PgProvider ¶
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 ¶
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()