db

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

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 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

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

Types

type ConnConfigCallback

type ConnConfigCallback = func(*pgxpool.Config) error

type ConnInitCallback

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

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, ...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)
}

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

Jump to

Keyboard shortcuts

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