database

package
v0.0.0-...-5597880 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithTx

func WithTx[T any](r *Repo) func() (T, Transacter, error)

WithTx is a helper function that returns a function that will return a new transaction and the querier to be used within the transaction. It allows us to define a subset of the queries to be used within the transaction.

Types

type Hooks

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

Hooks satisfies the sqlhook.Hooks interface

func NewHooks

func NewHooks() *Hooks

func (*Hooks) After

func (h *Hooks) After(ctx context.Context, query string, _ ...interface{}) (context.Context, error)

After hook will get the timestamp registered on the Before hook and print the elapsed time

func (*Hooks) Before

func (h *Hooks) Before(ctx context.Context, _ string, _ ...interface{}) (context.Context, error)

Before hook will print the query with it's args and return the context with the timestamp

func (*Hooks) OnError

func (h *Hooks) OnError(ctx context.Context, err error, query string, args ...interface{}) error

type Querier

type Querier interface {
	gensql.Querier
	WithTx(tx *sql.Tx) *gensql.Queries
}

type Repo

type Repo struct {
	Querier Querier
	// contains filtered or unexported fields
}

func New

func New(dbConnDSN string, maxIdleConn, maxOpenConn int) (*Repo, error)

func (*Repo) GetDB

func (r *Repo) GetDB() *sql.DB

func (*Repo) Metrics

func (r *Repo) Metrics() []prometheus.Collector

type Transacter

type Transacter interface {
	Commit() error
	Rollback() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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