postgres

package
v0.0.0-...-c3afde3 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package postgres provides a wrapper to connect to PostgreSQL. It also implements Unit of Work interface. See uow package for more info about Unit of Work.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyExist is returned when the new record violates unique key restriction.
	ErrAlreadyExist = errors.New("record already exist")
	// ErrNullDB is returned when nil is sent to mandatory db parameter.
	ErrNullDB = errors.New("db instance is null")
)

Functions

func NewDBWithPgx

func NewDBWithPgx(cfg Config) (*bun.DB, error)

NewDBWithPgx creates a bun.DB using pgx as driver.

Types

type BunDB

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

BunDB wraps uptrace/bun to comply with internal use.

func NewBunDB

func NewBunDB(db bun.IDB) (*BunDB, error)

NewBunDB creates an instance of Bun.

func (*BunDB) Begin

func (b *BunDB) Begin(ctx context.Context) (uow.Tx, error)

Begin begins the transaction.

func (*BunDB) Exec

func (b *BunDB) Exec(ctx context.Context, query string, args ...interface{}) (int64, error)

Exec executes the given query.

func (*BunDB) Query

func (b *BunDB) Query(ctx context.Context, dest interface{}, query string, args ...interface{}) error

Query queries the given query.

type BunTx

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

BunTx wraps uptrace/bun tx to comply with internal use.

func (*BunTx) Begin

func (t *BunTx) Begin(_ context.Context) (uow.Tx, error)

Begin begins the transaction

func (*BunTx) Commit

func (t *BunTx) Commit(_ context.Context) error

Commit commits the transaction.

func (*BunTx) Exec

func (t *BunTx) Exec(ctx context.Context, query string, args ...interface{}) (int64, error)

Exec executes the given query.

func (*BunTx) Query

func (t *BunTx) Query(ctx context.Context, dest interface{}, query string, args ...interface{}) error

Query queries the given query.

func (*BunTx) Rollback

func (t *BunTx) Rollback(_ context.Context) error

Rollback rolls back the transaction.

type Config

type Config struct {
	Host     string `env:"POSTGRES_HOST,default=localhost"`
	Port     string `env:"POSTGRES_PORT,default=5432"`
	User     string `env:"POSTGRES_USER,required"`
	Password string `env:"POSTGRES_PASSWORD,required"`
	Name     string `env:"POSTGRES_NAME,required"`
	SSLMode  string `env:"POSTGRES_SSL_MODE,default=disable"`
}

Config holds configuration for PostgreSQL.

Jump to

Keyboard shortcuts

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