database

package
v0.0.0-...-efc3f8c Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package database provides support for access the database.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound              = errors.New("not found")
	ErrInvalidID             = errors.New("ID isi not in its proper form")
	ErrAuthenticationFailure = errors.New("authentication failed")
	ErrForbidden             = errors.New("attempted action is not allowed")
)

Set of error variables for CRUD operations.

Functions

func NamedExecContext

func NamedExecContext(ctx context.Context, log *zap.SugaredLogger, db sqlx.ExtContext, query string, data interface{}) error

NamedExecContext is a helper function to execute a CUD operation with logging and tracing.

func NamedQuerySlice

func NamedQuerySlice(ctx context.Context, log *zap.SugaredLogger, db sqlx.ExtContext, query string, data interface{}, dest interface{}) error

[PS] Read operation which returns "multiple" results NamedQuerySlice is a helper function for executing queries that return a collection of data to be unmarshaled into a slice.

func NamedQueryStruct

func NamedQueryStruct(ctx context.Context, log *zap.SugaredLogger, db sqlx.ExtContext, query string, data interface{}, dest interface{}) error

[PS] Read operation which returns "single" results NamedQueryStruct is a helper function for executing queries that return a single value to be unmarshalled into a struct type.

func Open

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

[PS] Helper function Open knows how to open a database connection based on the configuration.

func StatusCheck

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

[PS] used for readiness probe in k8s StatusCheck returns nil if it can successfully talk to the database. It returns a non-nil error otherwise.

Types

type Config

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

Config is the required properties to use the database.

Jump to

Keyboard shortcuts

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