...

Package db

import "github.com/cybertec-postgresql/pgwatch/v3/internal/db"
Overview
Index

Overview ▾

Constants

const (
    pgConnRecycleSeconds = 1800      // applies for monitored nodes
    applicationName      = "pgwatch" // will be set on all opened PG connections for informative purposes
)

func DoesSchemaExist

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

DoesSchemaExist checks if schema exists

func GetTableColumns

func GetTableColumns(ctx context.Context, conn PgxIface, table string) (cols []string, err error)

GetTableColumns returns the list of columns for a given table

func Init

func Init(ctx context.Context, db PgxPoolIface, init ConnInitCallback) error

Init creates a new pool, check connection is establised. If not retries connection 3 times with delay 1s

func MarshallParamToJSONB

func MarshallParamToJSONB(v any) any

func Ping

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

type ConnConfigCallback

type ConnConfigCallback = func(*pgxpool.Config) error

type ConnInitCallback

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

type PgxConnIface

PgxConnIface is interface representing pgx connection

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

type PgxIface

PgxIface is common interface for every pgx class

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

type PgxPoolIface

PgxPoolIface is interface representing pgx pool

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
}

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 ...interface{}) (pgx.Rows, error)
}