db

package
v0.0.0-...-baf35ca Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

func Connect

func Connect(ctx context.Context, cfg Config, logger zerolog.Logger) (*pgxpool.Pool, error)

func Initialize

func Initialize(ctx context.Context, cfg Config, log zerolog.Logger) (*pgxpool.Pool, error)

func ResetSchema

func ResetSchema(ctx context.Context, pool *pgxpool.Pool) error

func RunInTx

func RunInTx(ctx context.Context, fn func(TxHandler) error) error

Types

type Config

type Config struct {
	Host      string `koanf:"host"`
	Port      int    `koanf:"port"`
	Name      string `koanf:"name"`
	User      string `koanf:"user"`
	Password  string `koanf:"password"`
	NoMigrate bool   `koanf:"nomigrate"`
	Trace     bool   `koanf:"trace"`
}

type Handler

type Handler interface {
	RunInTx(fn func(TxHandler) error) error
	Query(stmt string, args ...interface{}) (pgx.Rows, error)
	QueryRow(stmt string, args ...interface{}) pgx.Row
	Exec(stmt string, args ...interface{}) (pgconn.CommandTag, error)
	CopyFrom(tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
}

func Get

func Get(ctx context.Context) Handler

type SchemaInfo

type SchemaInfo struct {
	CurrentVersion int32
	LatestVersion  int32
	// contains filtered or unexported fields
}

func GetSchemaInfo

func GetSchemaInfo(ctx context.Context, pool *pgxpool.Pool) (SchemaInfo, error)

func (SchemaInfo) MigrateTo

func (s SchemaInfo) MigrateTo(ctx context.Context, ver int32) error

MigrateTo migrates to a specific version of the schema. Use '0' to undo all migrations.

type TxHandler

type TxHandler interface {
	Handler
	Tx() pgx.Tx
}

Jump to

Keyboard shortcuts

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