postgresdb

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ComponentName = "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() components.Component

func WithDSN

func WithDSN(dsn string) components.Option

func WithDatabase

func WithDatabase(database string) components.Option

func WithHost

func WithHost(host string) components.Option

func WithMigrations

func WithMigrations(location string) components.Option

func WithPassword

func WithPassword(password string) components.Option

func WithPort

func WithPort(port uint) components.Option

func WithUser

func WithUser(user string) components.Option

Types

type CloseTx

type CloseTx func(error) error

type Component

type Component struct {
	components.Base
	// contains filtered or unexported fields
}

func (*Component) Configure

func (c *Component) Configure(opts ...components.Option) error

func (*Component) Health

func (c *Component) Health(ctx context.Context) error

func (*Component) Pool

func (c *Component) Pool() *pgxpool.Pool

func (*Component) Shutdown

func (_ *Component) Shutdown() error

func (*Component) Start

func (c *Component) Start() (err error)

type ExecOption

type ExecOption func(*Executor)

func WithFilter

func WithFilter(filter QueryFilter) ExecOption

func WithTransaction

func WithTransaction(tx Tx) ExecOption

type Executor

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

func NewExecutor

func NewExecutor(dbpool *pgxpool.Pool, opts ...ExecOption) *Executor

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) Down

func (m *Migrations) Down() error

func (*Migrations) Up

func (m *Migrations) Up() error

type MigrationsConfig

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

type QueryFilter

type QueryFilter map[string][]string

func (*QueryFilter) AddWhere

func (qf *QueryFilter) AddWhere(sql string, args ...any) (string, []any)

type Tx

type Tx interface {
	pgx.Tx
}

Jump to

Keyboard shortcuts

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