postgres

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PsqlMaxParams = 65535
)

Variables

This section is empty.

Functions

func Error

func Error(message string, err error, fallback srverr.ErrCode) error

Types

type Closer

type Closer interface {
	Close() error
}

type DB

type DB struct {
	*sqlx.DB
	// contains filtered or unexported fields
}

func InitDB

func InitDB(ctx context.Context, conf DBConfig, opts ...Option) (*DB, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) WithTx

func (db *DB) WithTx(ctx context.Context, fn func(tx DBTX) error) error

type DBConfig added in v1.4.0

type DBConfig struct {
	Host     string
	Port     int
	Database string
	User     string
	Pass     string //nolint:gosec // internal config not exposed publicly
	Sslmode  string
	Options  map[string]string
}

type DBTX

type DBTX interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
	SelectContext(ctx context.Context, dest any, query string, args ...any) error
	GetContext(ctx context.Context, dest any, query string, args ...any) error
	NamedExecContext(ctx context.Context, query string, arg any) (sql.Result, error)
	NamedQuery(query string, arg any) (*sqlx.Rows, error)
}

type Option added in v1.4.0

type Option func(*dbOptions)

Option configures InitDB behaviour.

func Migration added in v1.4.0

func Migration(atlasBin string, db DBConfig, schema embed.FS) Option

Migration returns an Option that runs Atlas schema migrations against conf using devDB as the Atlas dev database and schema as the embedded SQL files.

type TestDB

type TestDB[D Closer] struct {
	// contains filtered or unexported fields
}

func NewServiceTestDB

func NewServiceTestDB[D Closer](
	t *testing.T,
	open func(ctx context.Context, conf, dev DBConfig) (D, error),
	seed func(t *testing.T, db D),
) *TestDB[D]

func (*TestDB[D]) Close

func (t *TestDB[D]) Close(ctx context.Context) error

func (*TestDB[D]) DB

func (t *TestDB[D]) DB() D

Jump to

Keyboard shortcuts

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