pgsql

package module
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 11 Imported by: 8

README

pgsql

Build Status codecov 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 IsCharacterNotInRepertoire added in v0.8.1

func IsCharacterNotInRepertoire(err error) bool

IsCharacterNotInRepertoire checks is error a character_not_in_repertoire

func IsErrorClass added in v0.8.1

func IsErrorClass(err error, class string) bool

IsErrorClass checks is error has given class

func IsErrorCode added in v0.8.1

func IsErrorCode(err error, code string) bool

IsErrorCode checks is error has given code

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 IsQueryCanceled added in v0.8.0

func IsQueryCanceled(err error) bool

IsQueryCanceled checks is error an query_canceled error (pq: canceling statement due to user request)

func IsSerializationFailure added in v0.14.0

func IsSerializationFailure(err error) bool

IsSerializationFailure checks is error a serialization_failure error (pq: could not serialize access due to read/write dependencies among transactions)

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 Iter added in v0.5.0

func Iter(q interface {
	QueryContext(context.Context, string, ...any) (*sql.Rows, error)
}, iter Iterator, query string, args ...any) error

func IterContext added in v0.5.0

func IterContext(ctx context.Context, q interface {
	QueryContext(context.Context, string, ...any) (*sql.Rows, error)
}, iter Iterator, query string, args ...any) error

func JSON added in v0.4.0

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

JSON wraps value with scanner and valuer

func Null added in v0.12.0

func Null[T comparable](v *T) interface {
	driver.Valuer
	sql.Scanner
}

func NullInt64 added in v0.9.0

func NullInt64(i *int64) interface {
	driver.Valuer
	sql.Scanner
}

NullInt64 scans null into zero int64 and convert zero into sql null

func NullString added in v0.2.5

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

NullString scans null into empty string and convert empty string into sql null

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 Iterator added in v0.5.0

type Iterator func(scan Scanner) error

type QueryContext added in v0.5.0

type QueryContext interface {
	QueryContext(context.Context, string, ...any) (*sql.Rows, error)
}

QueryContext interface

type Row added in v0.14.0

type Row struct {
	*sql.Row
}

func (*Row) Scan added in v0.14.0

func (r *Row) Scan(dest ...any) error

type Rows added in v0.14.0

type Rows struct {
	*sql.Rows
}

func (*Rows) Scan added in v0.14.0

func (r *Rows) Scan(dest ...any) error

type Scanner added in v0.5.0

type Scanner func(dest ...any) error

func Scan added in v0.14.0

func Scan(scan Scanner) Scanner

Scan wraps scanner with custom scanner

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 any) 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