pgx

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Wrapper utils around github.com/jackc/pgx

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPoolNotFound      = errors.New("connection pool not found")
	ErrPoolAlreadyExists = errors.New("connection pool already exists")
)

Functions

func InsertRow

func InsertRow(ctx context.Context, conn Conn, tableName string, data any, schema ...string) error

InsertRow inserts a new record into the specified table using the provided data.

func InsertRowJSON

func InsertRowJSON(ctx context.Context, conn Conn, tableName string, jsonData []byte, schema ...string) error

convenience functions for JSON input

func UpdateRow

func UpdateRow(ctx context.Context, conn Conn, tableName string, data any, where map[string]any, schema ...string) error

UpdateRow updates an existing record in the specified table using the provided data.

func UpdateRowJSON

func UpdateRowJSON(ctx context.Context, conn Conn, tableName string, jsonData []byte, where map[string]any, schema ...string) error

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

func (m *PoolManager) Add(ctx context.Context, cfg Pool, setActive ...bool) error

Add creates and adds a new connection pool. If `setActive=true` the connection is set as active/default connection

func (*PoolManager) Close

func (m *PoolManager) Close()

Close closes all connection pools.

func (*PoolManager) Get

func (m *PoolManager) Get(name string) (*pgxpool.Pool, error)

Get returns a connection pool by name.

func (*PoolManager) List

func (m *PoolManager) List() []string

List returns all connection names.

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.

Jump to

Keyboard shortcuts

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