postgres

package
v0.0.0-...-62bd34e Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDSN

func BuildDSN(params OpenParams) string

BuildDSN builds PostgreSQL connection string from open params.

func Exec

func Exec(ctx context.Context, db execer, query string, args ...any) error

Exec runs Exec on the provided db/tx.

func ExecOrWrap

func ExecOrWrap(ctx context.Context, db execer, query string, wrapMsg string, args ...any) error

ExecOrWrap runs Exec and wraps any error with the provided message.

func ExecRequireRow

func ExecRequireRow(ctx context.Context, db execer, query string, args ...any) error

ExecRequireRow runs Exec and returns pgx.ErrNoRows if it affected 0 rows.

func ExecRequireRowOrWrap

func ExecRequireRowOrWrap(ctx context.Context, db execer, query string, wrapMsg string, args ...any) error

ExecRequireRowOrWrap runs ExecRequireRow and: - returns nil if a row was affected, - returns pgx.ErrNoRows if 0 rows were affected, - wraps any other error with the provided message.

func InsertFlowEvent

func InsertFlowEvent(
	ctx context.Context,
	db execer,
	query string,
	correlationID string,
	actorType string,
	actorID string,
	eventType string,
	payload []byte,
	createdAt time.Time,
) error

InsertFlowEvent inserts a row into flow_events using the provided SQL query.

func NormalizeDatabaseName

func NormalizeDatabaseName(databaseName string) (string, error)

NormalizeDatabaseName validates and normalizes PostgreSQL database name input.

func Open deprecated

func Open(ctx context.Context, params OpenParams) (*sql.DB, error)

Open opens a compatibility database/sql connection.

Deprecated: use OpenPGXPool for all new code paths. Keep this helper only for integrations that explicitly require database/sql.

func OpenPGXPool

func OpenPGXPool(ctx context.Context, params OpenParams) (*pgxpool.Pool, error)

OpenPGXPool opens a pgx native pool and verifies it via Ping.

func OpenSQLDB

func OpenSQLDB(ctx context.Context, params OpenParams) (*sql.DB, error)

OpenSQLDB opens a compatibility database/sql connection using pgx stdlib and verifies it via Ping.

This helper is intended only for integrations that cannot work with pgxpool.

Types

type OpenParams

type OpenParams struct {
	Host     string
	Port     int
	DBName   string
	User     string
	Password string
	SSLMode  string

	PingTimeout time.Duration
}

OpenParams defines the minimal required connection settings for Postgres.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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