pgsql

package module
v0.0.0-...-3ebdfb1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: MIT Imports: 12 Imported by: 0

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

func IsCharacterNotInRepertoire(err error) bool

IsCharacterNotInRepertoire checks is error an character_not_in_repertoire

func IsErrorClass

func IsErrorClass(err error, class string) bool

IsErrorClass checks is error has given class

func IsErrorCode

func IsErrorCode(err error, code string) bool

IsErrorCode checks is error has given code

func IsForeignKeyViolation

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

IsForeignKeyViolation checks is error an foreign_key_violation

func IsInvalidTextRepresentation

func IsInvalidTextRepresentation(err error) bool

IsInvalidTextRepresentation checks is error an invalid_text_representation

func IsQueryCanceled

func IsQueryCanceled(err error) bool

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

func IsSerializationFailure

func IsSerializationFailure(err error) bool

IsSerializationFailure checks is error an 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

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

func IterContext

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

func JSON

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

JSON wraps value with scanner and valuer

func Null

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

func NullInt64

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

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

func NullString

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

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

func RunInTx

func RunInTx(db BeginTxer, opts *TxOptions, fn func(pgx.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(pgx.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

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

BeginTxer type

type Iterator

type Iterator func(scan Scanner) error

type QueryContext

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

QueryContext interface

type Row

type Row struct {
	*sql.Row
}

func (*Row) Scan

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

type Rows

type Rows struct {
	*sql.Rows
}

func (*Rows) Scan

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

type Scanner

type Scanner func(dest ...any) error

func Scan

func Scan(scan Scanner) Scanner

Scan wraps scanner with custom scanner

type TxOptions

type TxOptions struct {
	pgx.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