repo

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package repo provide helpers for Data Access Layer.

Index

Constants

View Source
const (
	PostgresUniqueViolation     = "unique_violation"
	PostgresForeignKeyViolation = "foreign_key_violation"
)

Error names.

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 v0.4.0

func MySQLDuplicateEntry(err error) bool

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

func PostgresErrName added in v0.4.0

func PostgresErrName(err error, name string) bool

PostgresErrName returns true if err is PostgreSQL error with given name.

func PostgresFromDuration added in v0.5.0

func PostgresFromDuration(dur time.Duration) *pgtype.Interval

PostgresFromDuration creates new interval from duration.

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 v0.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 PostgresConfig added in v0.4.0

type PostgresConfig struct {
	Postgres         *def.PostgresConfig
	GoosePostgresDir string
	SchemaVersion    int64
	Metric           Metrics
	ReturnErrs       []error // List of app.Err… returned by DAL methods.
}

PostgresConfig contains repo configuration.

type PostgresInet added in v0.5.0

type PostgresInet struct {
	*pgtype.Inet
}

PostgresInet is a wrapper around pgtype.Inet.

func PostgresFromIP added in v0.5.0

func PostgresFromIP(ip net.IP) *PostgresInet

PostgresFromIP creates new Inet from ip.

func (*PostgresInet) IP added in v0.5.0

func (inet *PostgresInet) IP() net.IP

IP returns nil or src.IPNet.IP.

func (*PostgresInet) Scan added in v0.5.0

func (inet *PostgresInet) Scan(src interface{}) error

Scan implements the database/sql Scanner interface.

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 v0.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 NewPostgres added in v0.4.0

func NewPostgres(ctx Ctx, goose *goosepkg.Instance, cfg PostgresConfig) (_ *Repo, err error)

NewPostgres 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