xpg

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrWrap

func ErrWrap(e error, process string, args ...interface{}) error

ErrWrap takes error returned from Postgres and returns structured error. Basically, we work with three database related kinds of errors: ErrNotFound for empty results, Coflict for insert/update violating data integrity, ErrInternal for all other kind of db errors.

func ErrWrapf

func ErrWrapf(e error, process string, fmt string, args ...interface{}) error

ErrWrapf takes error returned from Postgres and returns structured error. Basically, we work with three database related kinds of errors: ErrNotFound for empty results, Coflict for insert/update violating data integrity, ErrInternal for all other kind of db errors.

func Parse

func Parse(dial string) (*pg.Options, error)

Parse will parse url and return options

func RunInTransaction

func RunInTransaction(ctx context.Context, db orm.DB, fn func(*pg.Tx) error) error

RunInTransaction is just like orm's RunInTransaction except it enforces errdef.ErrSet

Types

type Adapter

type Adapter struct {
	DB         orm.DB
	Driver     *PGDriver
	RetryCount int
}

Adapter is the go-pg adapter implementation.

func NewAdapter

func NewAdapter(db orm.DB) *Adapter

NewAdapter creates a new go-pg adapter.

func (*Adapter) Do

func (a *Adapter) Do(ctx context.Context, db orm.DB, fn func(context.Context, orm.DB) error) error

Do executes given function with taking care about the retries of the connection.

func (*Adapter) DoTx

func (a *Adapter) DoTx(ctx context.Context, db orm.DB, fn func(context.Context, *pg.Tx) error) error

DoTx executes given function in a transaction taking care about the retries of the connection.

func (*Adapter) Err

func (a *Adapter) Err(err error) *cgerrors.Error

Err handlers given error returning a cgerrors.Error

type Conn

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

Conn provides *pg.DB - a database handle representing a pool of zero or more underlying connections. It's safe for concurrent use by multiple goroutines.

func NewConn

func NewConn(config *pg.Options) *Conn

NewConn creates a new Conn.

func (*Conn) AddLogger

func (c *Conn) AddLogger(log Logger)

AddLogger will add xlog to database

func (*Conn) Close

func (c *Conn) Close()

Close closes the database client, releasing any open resources. It is rare to Close a DB, as the DB handle is meant to be long-lived and shared between many goroutines.

func (*Conn) Get

func (c *Conn) Get() *pg.DB

Get returns a database handle representing a pool of zero or more underlying connections. It's safe for concurrent use by multiple goroutines.

type Log

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

Log is regular xlog

func (*Log) AfterQuery

func (log *Log) AfterQuery(ctx context.Context, event *pg.QueryEvent) error

AfterQuery as after query went back

func (*Log) BeforeQuery

func (log *Log) BeforeQuery(ctx context.Context, event *pg.QueryEvent) (context.Context, error)

BeforeQuery as before query is executed for log entry

type Logger

type Logger interface {
	pg.QueryHook
}

Logger defining format for various loggers

func NewLogger

func NewLogger(strip int) Logger

NewLogger creates new xlog, specify strip if you want queries longer then x chars be striped

type PGDriver

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

PGDriver is an implementation of the xservice.Driver for the go-pg.

func NewDriver

func NewDriver() *PGDriver

NewDriver creates a new driver implementation for the go-pg.

func (*PGDriver) CanRetry

func (p *PGDriver) CanRetry(err error) bool

CanRetry implements xservice.Driver interface.

func (*PGDriver) CustomErrorCode

func (p *PGDriver) CustomErrorCode(class string, code cgerrors.ErrorCode)

CustomErrorCode overwrites default error map for given class, which would result in given code.

func (*PGDriver) DriverName added in v0.0.16

func (p *PGDriver) DriverName() string

DriverName gets the name of the PGDriver.

func (*PGDriver) Err

func (p *PGDriver) Err(err error) *cgerrors.Error

Err converts given error into a cgerrors.Error.

func (*PGDriver) ErrorCode

func (p *PGDriver) ErrorCode(err error) cgerrors.ErrorCode

ErrorCode implements xservice.Driver interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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