database

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = errors.New("not found")
	ErrWrongInputData = errors.New("wrong input data")
	ErrAlreadyExists  = errors.New("already exists")
)

Functions

func Error

func Error(err error) error

Error extracting database error

func Get

func Get[T any](ctx context.Context, database *Database, builder squirrel.SelectBuilder) (*T, error)

Get fetching a row from the database. There is a restriction on using generic, that's why it's a method for now. Takes data from the database and unpacks it into the model.

func NewConfig

func NewConfig(url string, l *zap.Logger) (*pgxpool.Config, error)

func Select

func Select[T any](ctx context.Context, database *Database, builder squirrel.SelectBuilder) ([]T, error)

Select selecting data from the database. There is a restriction on using generic, that's why it's a method for now. Takes data from the database and unpacks it into the model.

Types

type Database

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

func NewForURL

func NewForURL(url string, l *zap.Logger) (*Database, error)

func (Database) Delete

func (r Database) Delete(ctx context.Context, builder squirrel.DeleteBuilder) (rowsAffected int64, err error)

func (Database) ExecuteRaw

func (r Database) ExecuteRaw(ctx context.Context, sql string, args ...any) (rowsAffected int64, err error)

func (Database) GetRaw

func (r Database) GetRaw(ctx context.Context, dst any, sql string, args ...any) error

func (Database) Insert

func (r Database) Insert(ctx context.Context, builder squirrel.InsertBuilder) (rowsAffected int64, err error)

func (Database) QueryBuilder

func (r Database) QueryBuilder() query.Builder

func (Database) SelectRaw

func (r Database) SelectRaw(ctx context.Context, dst any, sql string, args ...any) error

func (Database) Transaction

func (r Database) Transaction(ctx context.Context) (pgx.Tx, error)

func (Database) Update

func (r Database) Update(ctx context.Context, builder squirrel.UpdateBuilder) (rowsAffected int64, err error)

func (Database) WithTx

func (r Database) WithTx(
	ctx context.Context,
	handler func(ctx context.Context, queryRunner *transaction.Executor) error,
) error

type Logger

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

func NewLogger

func NewLogger(l *zap.Logger) Logger

func (Logger) Log

func (l Logger) Log(_ context.Context, level tracelog.LogLevel, msg string, data map[string]interface{})

type Table

type Table string

func (Table) String

func (t Table) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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