pgxkit

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = errors.New("not found")
	ErrAlreadyExists = errors.New("already exists")
)

Functions

func Exec

func Exec(ctx context.Context, e Execer, sql string, args ...any) error

func Open

func Open(ctx context.Context, url string) (*pgxpool.Pool, error)

func Query

func Query[T any](ctx context.Context, q Queryer, sql string, args ...any) ([]T, error)

func QueryRow

func QueryRow[T any](ctx context.Context, q Queryer, sql string, args ...any) (T, error)

func QueryValue

func QueryValue[T any](ctx context.Context, q Queryer, sql string, args ...any) (T, error)

Types

type Acquirer

type Acquirer interface {
	Acquire(ctx context.Context) (*pgxpool.Conn, error)
}

type BatchSender

type BatchSender interface {
	SendBatch(ctx context.Context, b *pgx.Batch) (br pgx.BatchResults)
}

type Beginner

type Beginner interface {
	// Begin starts a new pgx.Tx. It may be a true transaction or a pseudo nested transaction implemented by savepoints.
	Begin(ctx context.Context) (pgx.Tx, error)
}

type Client

type Client interface {
	Opener
	Connector
	DB
	Migrator
}

func NewClient

func NewClient(url string, opts ...ClientOption) Client

type ClientOption

type ClientOption interface {
	// contains filtered or unexported methods
}

type ClientOptionFunc

type ClientOptionFunc func(*client)

func WithLogger

func WithLogger(log *slog.Logger) ClientOptionFunc

func WithMigrations

func WithMigrations(fsys fs.FS, act MigrateAction) ClientOptionFunc

type Closer

type Closer interface{ Close() }

type Connector

type Connector interface {
	Conn(ctx context.Context) (*pgx.Conn, error)
}

type Copier

type Copier interface {
	CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
}

type Execer

type Execer interface {
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
}

type MigrateAction

type MigrateAction string
const (
	MigrateUp   MigrateAction = "up"
	MigrateDown MigrateAction = "down"
)

func ParseMigrateAction

func ParseMigrateAction(s string) (MigrateAction, error)

type MigrateActionFlag

type MigrateActionFlag struct {
	IsSet bool
	Val   MigrateAction
}

func (*MigrateActionFlag) Set

func (f *MigrateActionFlag) Set(s string) error

func (*MigrateActionFlag) String

func (f *MigrateActionFlag) String() string

type Migrator

type Migrator interface {
	Migrate(ctx context.Context, fsys fs.FS, act MigrateAction) error
}

type NamedArgs

type NamedArgs = pgx.NamedArgs

type Opener

type Opener interface {
	Open(ctx context.Context) error
}

type Queryer

type Queryer interface {
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
}

type Tx

type Tx interface {
	Beginner
	Copier
	Queryer
	Execer
	BatchSender
	Commit(context.Context) error
	Rollback(context.Context) error
}

Jump to

Keyboard shortcuts

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