postgresdb

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModuleName = "postgresdb"
)

Variables

View Source
var (
	ErrNotFound       error = fmt.Errorf("resource not found")
	ErrNoDBConnection error = fmt.Errorf("database connection pool not set")
	ErrNoTransaction  error = fmt.Errorf("transaction has not been started")
)

Functions

func BuildDSN

func BuildDSN(user, password, host, database string, port uint, queryOpts ...string) *url.URL

func New

func New() modules.Module

func WithDSN

func WithDSN(dsn string) modules.Option

func WithDatabase

func WithDatabase(database string) modules.Option

func WithHost

func WithHost(host string) modules.Option

func WithMigrations

func WithMigrations(cfg *MigrationsConfig) modules.Option

func WithMigrationsLocation

func WithMigrationsLocation(location string) modules.Option

func WithMigrationsSchemaName

func WithMigrationsSchemaName(schemaName string) modules.Option

func WithMigrationsTable

func WithMigrationsTable(table string) modules.Option

func WithPassword

func WithPassword(password string) modules.Option

func WithPort

func WithPort(port uint) modules.Option

func WithUser

func WithUser(user string) modules.Option

Types

type CloseTx

type CloseTx func(error) error

type ExecOption

type ExecOption func(*Executor)

func WithFilter

func WithFilter(filter query.Filter) ExecOption

WithFilter sets the query.Filter option, which applies all filters to all queries that are to be executed on a executor where this option is passed to. To remove filters from a query, nil or query.Filter{} should be passed here.

func WithLimit

func WithLimit(limit query.Limit) ExecOption

WithLimit sets the query.Limit option, which will apply the "OFFSET" and "LIMIT" statements to all the queries that will be executed with the executor this option is passed to. To remove limits from a query, nil or query.Filter{} should be passed here.

func WithOrderBy

func WithOrderBy(orderBy query.OrderBy) ExecOption

WithOrderBy sets the query.OrderBy option, which applies the "ORDER BY" statement to all the queries that will be executed with the executor this option is passed to. To remove orders from a query, nil or query.Filter{} should be passed here.

func WithTransaction deprecated

func WithTransaction(tx Tx) ExecOption

Deprecated: WithTransaction is no longer to be used as the Executor is now receiving a Querier interface which can be either a DBPool or a Transaction. WithTransaction sets the Tx transaction object to the executor. All queries executed on the executor where this option is given, will be executed using this transaction.

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

Executor provides the same query methods as pgx execution types, but extends them with support for ExecOptions. These options let users modify query behavior by applying criteria such as WHERE, LIMIT, or ORDER BY clauses.

func NewExecutor

func NewExecutor(querier Querier, opts ...ExecOption) *Executor

NewExecutor instantiates the Executor with the Querier and applies ExecOptions to it.

func (*Executor) Exec

func (e *Executor) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)

func (*Executor) Query

func (e *Executor) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)

func (*Executor) QueryRow

func (e *Executor) QueryRow(ctx context.Context, sql string, args ...any) (pgx.Row, error)

type Migrations

type Migrations struct {
	// contains filtered or unexported fields
}

func InitMigrations

func InitMigrations(cfg *MigrationsConfig) (*Migrations, error)

func (*Migrations) Close

func (m *Migrations) Close() error

func (*Migrations) Down

func (m *Migrations) Down() error

func (*Migrations) Up

func (m *Migrations) Up() error

type MigrationsConfig

type MigrationsConfig struct {
	Pool       *pgxpool.Pool
	Location   string
	Table      string
	SchemaName string
}

type Module

type Module struct {
	modules.Base
	// contains filtered or unexported fields
}

func (*Module) Configure

func (m *Module) Configure(opts ...modules.Option) error

func (*Module) Health

func (m *Module) Health(ctx context.Context) error

func (*Module) Pool

func (m *Module) Pool() *pgxpool.Pool

func (*Module) Shutdown

func (m *Module) Shutdown() error

func (*Module) Start

func (m *Module) Start() (err error)

type Querier

type Querier interface {
	Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
	Query(context.Context, string, ...any) (pgx.Rows, error)
	QueryRow(context.Context, string, ...any) pgx.Row
}

type Tx

type Tx interface {
	pgx.Tx
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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