Documentation
¶
Overview ¶
Wrapper utils around github.com/jackc/pgx
Index ¶
- Variables
- func InsertRow(ctx context.Context, conn Conn, tableName string, data any, schema ...string) error
- func InsertRowJSON(ctx context.Context, conn Conn, tableName string, jsonData []byte, ...) error
- func UpdateRow(ctx context.Context, conn Conn, tableName string, data any, ...) error
- func UpdateRowJSON(ctx context.Context, conn Conn, tableName string, jsonData []byte, ...) error
- type Conn
- type Pool
- type PoolManager
- func (m *PoolManager) Active() (*pgxpool.Pool, error)
- func (m *PoolManager) Add(ctx context.Context, cfg Pool, setActive ...bool) error
- func (m *PoolManager) Close()
- func (m *PoolManager) Get(name string) (*pgxpool.Pool, error)
- func (m *PoolManager) List() []string
- func (m *PoolManager) Remove(name string) error
- func (m *PoolManager) SetActive(name string) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrPoolNotFound = errors.New("connection pool not found") ErrPoolAlreadyExists = errors.New("connection pool already exists") )
Functions ¶
func InsertRowJSON ¶
func InsertRowJSON(ctx context.Context, conn Conn, tableName string, jsonData []byte, schema ...string) error
convenience functions for JSON input
Types ¶
type Conn ¶
type Conn interface {
// Exec executes a SQL statement in the context of the given context 'ctx'.
// It returns a CommandTag containing details about the executed statement,
// or an error if there was an issue during execution.
Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
// Query executes a SQL query in the context of the given context 'ctx'.
// It returns a Rows object that can be used to iterate over the results
// of the query, or an error if there was an issue during execution.
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
// QueryRow executes a query that is expected to return at most one row.
// It returns a Row object that can be used to retrieve the single row,
// or an error if there was an issue during execution.
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
// Begin starts a transaction. Unlike database/sql, the context only affects the begin command.
// i.e. there is no auto-rollback on context cancellation.
Begin(ctx context.Context) (pgx.Tx, error)
// BeginTx starts a transaction with txOptions determining the transaction mode. Unlike database/sql,
// the context only affects the begin command. i.e. there is no auto-rollback on context cancellation.
BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
}
Conn defines a common interface for interacting with PostgreSQL connections. This interface abstracts away the underlying connection type (e.g., pgx.Conn, pgxpool.Conn) allowing for easier use within frameworks and libraries that need to work with both single connections and connection pools.
type Pool ¶
type Pool struct {
Config *pgxpool.Config // Takes precedence over ConnString
Name string
ConnString string // Used if Config is nil
}
Pool represents a named connection configuration.
type PoolManager ¶
type PoolManager struct {
// contains filtered or unexported fields
}
PoolManager manages one or more named *pgxpool.Pool's.
func NewPoolManager ¶
func NewPoolManager() *PoolManager
NewPoolManager returns a new connection manager.
func (*PoolManager) Active ¶
func (m *PoolManager) Active() (*pgxpool.Pool, error)
Active returns the current active connection pool.
func (*PoolManager) Add ¶
Add creates and adds a new connection pool. If `setActive=true` the connection is set as active/default connection
func (*PoolManager) Get ¶
func (m *PoolManager) Get(name string) (*pgxpool.Pool, error)
Get returns a connection pool by name.
func (*PoolManager) Remove ¶
func (m *PoolManager) Remove(name string) error
Remove closes and removes a connection pool.
func (*PoolManager) SetActive ¶
func (m *PoolManager) SetActive(name string) error
SetActive changes the active connection.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package role provides functions for managing PostgreSQL roles, including creating, updating, retrieving, and deleting roles.
|
Package role provides functions for managing PostgreSQL roles, including creating, updating, retrieving, and deleting roles. |
|
Package schema provides functionality for caching PostgreSQL objects' metadata eg schema of tables / views, function def etc.
|
Package schema provides functionality for caching PostgreSQL objects' metadata eg schema of tables / views, function def etc. |