const ( pgConnRecycleSeconds = 1800 // applies for monitored nodes applicationName = "pgwatch" // will be set on all opened PG connections for informative purposes )
func DoesSchemaExist(ctx context.Context, conn PgxIface, schema string) (bool, error)
DoesSchemaExist checks if schema exists
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(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(v any) any
func Ping(ctx context.Context, connStr string) error
type ConnConfigCallback = func(*pgxpool.Config) error
type ConnInitCallback = func(context.Context, PgxIface) error
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 }
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) }
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(ctx context.Context, connStr string, callbacks ...ConnConfigCallback) (PgxPoolIface, error)
New create a new pool
func NewWithConfig(ctx context.Context, connConfig *pgxpool.Config, callbacks ...ConnConfigCallback) (PgxPoolIface, error)
NewWithConfig creates a new pool with a given config
type Querier interface { Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error) }