pgsql

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT Imports: 8 Imported by: 8

README

pgsql

Build Status Coverage Status Go Report Card GoDoc

pgsql is the helper functions for postgres

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAbortTx = errors.New("pgsql: abort tx")

ErrAbortTx rollbacks transaction and return nil error

Functions

func IsForeignKeyViolation added in v0.2.8

func IsForeignKeyViolation(err error, constraint ...string) bool

IsForeignKeyViolation checks is error an foreign_key_violation

func IsInvalidTextRepresentation added in v0.2.2

func IsInvalidTextRepresentation(err error) bool

IsInvalidTextRepresentation checks is error an invalid_text_representation

func IsUniqueViolation

func IsUniqueViolation(err error, constraint ...string) bool

IsUniqueViolation checks is error an unique_violation with given constraint, constraint can be empty to ignore constraint name checks

func JSON added in v0.4.0

func JSON(value interface{}) interface {
	driver.Valuer
	sql.Scanner
}

JSON wraps value with scanner and valuer

func NullString added in v0.2.5

func NullString(s *string) interface {
	driver.Valuer
	sql.Scanner
}

NullString scans null into empty string

func NullTime added in v0.2.4

func NullTime(t *time.Time) interface {
	driver.Valuer
	sql.Scanner
}

NullTime likes Time but wrap time.Time with scanner

func RunInTx

func RunInTx(db BeginTxer, opts *TxOptions, fn func(*sql.Tx) error) error

RunInTx runs fn inside retryable transaction.

see RunInTxContext for more info.

func RunInTxContext

func RunInTxContext(ctx context.Context, db BeginTxer, opts *TxOptions, fn func(*sql.Tx) error) error

RunInTxContext runs fn inside retryable transaction with context. It use Serializable isolation level if tx options isolation is setted to sql.LevelDefault.

RunInTxContext DO NOT handle panic. But when panic, it will rollback the transaction.

Types

type BeginTxer added in v0.2.1

type BeginTxer interface {
	BeginTx(context.Context, *sql.TxOptions) (*sql.Tx, error)
}

BeginTxer type

type Time added in v0.2.3

type Time struct {
	time.Time
}

Time is the time.Time but can scan null into empty

func (*Time) Scan added in v0.2.3

func (t *Time) Scan(src interface{}) error

Scan implements Scanner interface

func (Time) Value added in v0.2.3

func (t Time) Value() (driver.Value, error)

Value implements Valuer interface

type TxOptions

type TxOptions struct {
	sql.TxOptions
	MaxAttempts int
}

TxOptions is the transaction options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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