db

package
v4.88.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 13 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoHost        = errors.New("no host for database connection")
	ErrNoTransaction = errors.New("no transaction in context, please wrap with DoAtomic()")
	SQLTimeout       = time.Second * 5
)

Functions

func StoreTx

func StoreTx(ctx context.Context, tx pgx.Tx) context.Context

Types

type Config

type Config struct {
	Host    string
	User    string
	Pass    string
	Name    string
	SSLMode string
	Port    uint
	MinConn uint
	MaxConn uint
}

func Flags

func Flags(fs *flag.FlagSet, prefix string, overrides ...flags.Override) *Config

type Database added in v4.24.0

type Database interface {
	Ping(context.Context) error
	Close()
	Begin(context.Context) (pgx.Tx, error)
	Query(context.Context, string, ...any) (pgx.Rows, error)
	QueryRow(context.Context, string, ...any) pgx.Row
	Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
}

type Service added in v4.64.0

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

func New

func New(ctx context.Context, config *Config, tracerProvider trace.TracerProvider) (*Service, error)

func (*Service) Bulk added in v4.64.0

func (s *Service) Bulk(ctx context.Context, fetcher func() ([]any, error), schema, table string, columns ...string) (err error)

func (*Service) Close added in v4.64.0

func (s *Service) Close()

func (*Service) Create added in v4.64.0

func (s *Service) Create(ctx context.Context, query string, args ...any) (id uint64, err error)

func (*Service) DoAtomic added in v4.64.0

func (s *Service) DoAtomic(ctx context.Context, action func(context.Context) error) (err error)

func (*Service) Enabled added in v4.64.0

func (s *Service) Enabled() bool

func (*Service) Exec added in v4.64.0

func (s *Service) Exec(ctx context.Context, query string, args ...any) error

func (*Service) Get added in v4.64.0

func (s *Service) Get(ctx context.Context, scanner func(pgx.Row) error, query string, args ...any) error

func (*Service) List added in v4.64.0

func (s *Service) List(ctx context.Context, scanner func(pgx.Rows) error, query string, args ...any) error

func (*Service) One added in v4.64.0

func (s *Service) One(ctx context.Context, query string, args ...any) error

func (*Service) Ping added in v4.64.0

func (s *Service) Ping(ctx context.Context) error

func (*Service) Query added in v4.64.0

func (s *Service) Query(ctx context.Context, query string, args ...any) (rows pgx.Rows, err error)

func (*Service) QueryRow added in v4.64.0

func (s *Service) QueryRow(ctx context.Context, query string, args ...any) pgx.Row

Jump to

Keyboard shortcuts

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