database

package
v0.0.0-...-ac0e98d Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package database provides support for accessing the database.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound        = sql.ErrNoRows
	ErrUniqueViolation = errors.New("duplicated entry")
	ErrUndefinedTable  = errors.New("undefined table")
)

Set of error variables for CRUD operations.

Functions

func NamedExec

func NamedExec(log *zerolog.Logger, db sqlx.Ext, query string, data any) (err error)

func NamedQuerySlice

func NamedQuerySlice[T any](log *zerolog.Logger, db sqlx.Ext, query string, data any, dest *[]T) (err error)

func NamedQueryStruct

func NamedQueryStruct(log *zerolog.Logger, db sqlx.Ext, query string, data any, dest any) (err error)

func Open

func Open(cfg Config) (*sqlx.DB, error)

Open knows how to open a database connection based on the configuration.

func Ping

func Ping(ctx context.Context, db *sqlx.DB) error

Ping returns nil if it can successfully talk to the database. It returns a non-nil error otherwise.

func WithinTran

func WithinTran(log *zerolog.Logger, db *sqlx.DB, fn func(*sqlx.Tx) error) error

WithinTran runs passed function and do commit/rollback at the end.

Types

type Config

type Config struct {
	User         string
	Password     string
	Host         string
	Name         string
	MaxIdleConns int
	MaxOpenConns int
	DisableTLS   bool
}

Jump to

Keyboard shortcuts

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