postgres

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const Timeout = 3 * time.Second

default query timeout

Variables

View Source
var (
	ErrNotFound = errors.New("postgres: not found")
	ErrConflict = errors.New("postgres: conflict")

	// sentinel error used to rollback transactions
	ErrRollback = errors.New("postgres: rollback")
)

TODO: add metadata to errors to make em more useful:

  • what already exists
  • what was missing
  • what column(s) caused the conflict

Functions

func CheckCreateError

func CheckCreateError(err error) error

func CheckDeleteError

func CheckDeleteError(err error) error

func CheckListError

func CheckListError(err error) error

func CheckReadError

func CheckReadError(err error) error

func CheckUpdateError

func CheckUpdateError(err error) error

func Connect

func Connect(uri string) (*pgx.Conn, error)

func ConnectPool

func ConnectPool(uri string) (*pgxpool.Pool, error)

func Migrate

func Migrate(conn Conn, files fs.FS) ([]string, error)

Types

type Conn

type Conn interface {
	Begin(ctx context.Context) (pgx.Tx, error)
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
}

Common interface for pgx.Conn, pgx.Pool, pgx.Tx, etc https://github.com/jackc/pgx/issues/644

Jump to

Keyboard shortcuts

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