store

package
v3.30.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package store provides utilities when working with a database.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnavailable is an error that indicates an unavailable database.
	ErrUnavailable = errors.DefineUnavailable("database_unavailable", "database unavailable")
	// ErrNotFound is an error that indicates a missing entity.
	ErrNotFound = errors.DefineNotFound("not_found", "no results found")
	// ErrDriver is an error that indicates a driver error.
	ErrDriver = errors.Define("driver", "driver error")
	// ErrIDTaken is returned when an entity can not be created because the ID is already taken.
	ErrIDTaken = errors.DefineAlreadyExists("id_taken", "ID already taken, choose a different one and try again")
	// ErrEUITaken is returned when an entity can not be created because the EUI is already taken.
	ErrEUITaken = errors.DefineAlreadyExists("eui_taken", "EUI already taken")
)

Functions

func NewLoggerHook added in v3.24.1

func NewLoggerHook(logger log.Interface, opts ...LoggerHookOption) bun.QueryHook

NewLoggerHook returns a new bun.QueryHook that logs queries to the logger.

func OpenDB

func OpenDB(ctx context.Context, databaseURI string) (*sql.DB, error)

OpenDB opens the database connection.

func WrapDriverError added in v3.24.0

func WrapDriverError(err error) error

WrapDriverError wraps a driver error with the corresponding error definition.

Types

type DriverError added in v3.24.0

type DriverError struct {
	Code       string
	Message    string
	Detail     string
	Table      string
	Column     string
	Constraint string
}

DriverError encapsulates the PostgreSQL error data.

func (*DriverError) Attributes added in v3.24.0

func (e *DriverError) Attributes() []any

Attributes gets the DriverError attributes.

func (*DriverError) GetError added in v3.24.0

func (e *DriverError) GetError() error

GetError gets the corresponding error definition.

type LoggerHookOption added in v3.24.1

type LoggerHookOption func(*loggerHook)

LoggerHookOption is an option for the LoggerHook.

Jump to

Keyboard shortcuts

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