repo

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package repo provide helpers for Data Access Layer.

Index

Constants

View Source
const MySQLMaxKeySize = 191

MySQLMaxKeySize for indexed MySQL utf8mb4 CHAR/VARCHAR column.

Variables

View Source
var (
	ErrSchemaVer = errors.New("unsupported DB schema version")
)

Errors.

Functions

func MySQLDuplicateEntry added in v1.4.0

func MySQLDuplicateEntry(err error) bool

MySQLDuplicateEntry returns true if err is mysql error "Duplicate entry…".

Types

type Ctx

type Ctx = context.Context

Ctx is a synonym for convenience.

type Metrics

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

Metrics contains general metrics for DAL methods.

func NewMetrics

func NewMetrics(reg *prometheus.Registry, namespace, subsystem string, methodsFrom interface{}) (metric Metrics)

NewMetrics registers and returns common DAL metrics used by all services (namespace).

type MySQLConfig added in v1.4.0

type MySQLConfig struct {
	MySQL         *mysql.Config
	GooseMySQLDir string
	SchemaVersion int64
	Metric        Metrics
	ReturnErrs    []error // List of app.Err… returned by DAL methods.
}

MySQLConfig contains repo configuration.

type Repo

type Repo struct {
	DB        *sqlxx.DB
	SchemaVer *schemaver.SchemaVer
	// contains filtered or unexported fields
}

Repo provides access to storage.

func NewMySQL added in v1.4.0

func NewMySQL(ctx Ctx, goose *goosepkg.Instance, cfg MySQLConfig) (*Repo, error)

NewMySQL creates and returns new Repo. It will also run required DB migrations and connects to DB.

func (*Repo) Close

func (r *Repo) Close()

Close closes connection to DB.

func (*Repo) NoTx

func (r *Repo) NoTx(f func() error) (err error)

NoTx provides DAL method wrapper with: - converting sqlx errors which are actually bugs into panics, - ensure valid schema version while accessing DB, - general metrics for DAL methods, - wrapping errors with DAL method name.

func (*Repo) Tx

func (r *Repo) Tx(ctx Ctx, opts *sql.TxOptions, f func(*sqlxx.Tx) error) (err error)

Tx provides DAL method wrapper with: - converting sqlx errors which are actually bugs into panics, - ensure valid schema version while accessing DB, - general metrics for DAL methods, - wrapping errors with DAL method name, - transaction.

Jump to

Keyboard shortcuts

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