db

package
v5.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package db provides common functionality to work with databases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoesSchemaExist

func DoesSchemaExist(ctx context.Context, conn PgxIface, schema string) (bool, error)

DoesSchemaExist checks if schema exists

func Init

Init checks if connection is establised. If not, retries connection 3 times with delay 1s

func IsClientOnSameHost

func IsClientOnSameHost(conn PgxIface) (bool, error)

Function to determine if the client is connected to the same host as the PostgreSQL server

func IsPgConnStr

func IsPgConnStr(arg string) bool

func MarshallParamToJSONB

func MarshallParamToJSONB(v any) any

func NeedsMigration

func NeedsMigration(storage any, needsMigrationErr error) error

func Ping

func Ping(ctx context.Context, connStr string) error

Types

type ConnConfigCallback

type ConnConfigCallback = func(*pgxpool.Config) error

type ConnInitCallback

type ConnInitCallback = func(context.Context, PgxIface) error

type Migrator

type Migrator interface {
	Migrate() error
	NeedsMigration() (bool, error)
}

Migrator is an interface for database schema migration

type PgxConnIface

type PgxConnIface interface {
	PgxIface
	BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
	Close(ctx context.Context) error
	Ping(ctx context.Context) error
}

PgxConnIface is interface representing pgx connection

type PgxIface

type PgxIface interface {
	Begin(ctx context.Context) (pgx.Tx, error)
	Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
	QueryRow(context.Context, string, ...any) pgx.Row
	Query(ctx context.Context, query string, args ...any) (pgx.Rows, error)
	CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
}

PgxIface is common interface for every pgx class

type PgxPoolIface

type PgxPoolIface interface {
	PgxIface
	Acquire(ctx context.Context) (*pgxpool.Conn, error)
	BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
	Close()
	Config() *pgxpool.Config
	Ping(ctx context.Context) error
	Stat() *pgxpool.Stat
}

PgxPoolIface is interface representing pgx pool

func New

func New(ctx context.Context, connStr string, callbacks ...ConnConfigCallback) (PgxPoolIface, error)

New create a new pool

func NewWithConfig

func NewWithConfig(ctx context.Context, connConfig *pgxpool.Config, callbacks ...ConnConfigCallback) (PgxPoolIface, error)

NewWithConfig creates a new pool with a given config

type Querier

type Querier interface {
	Query(ctx context.Context, query string, args ...any) (pgx.Rows, error)
}

Jump to

Keyboard shortcuts

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