pgutil

package
v0.0.0-...-c537d22 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ErrCodeConflict   pq.ErrorCode = "23503"
	ErrCodeIncomplete pq.ErrorCode = "22P02"
	ErrCodeDuplicate  pq.ErrorCode = "23505"
)

Variables

View Source
var (
	ErrByteFormatError = errors.New("unexpected format. Expecting a bit array")
)
View Source
var Psql = squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar)

Functions

func ApplyOperators

func ApplyOperators(query *squirrel.SelectBuilder, config []ISearchOperatorConfig, ops operator.Operators, prefix string)

func ApplySort

func ApplySort(activeSorts []string, query *squirrel.SelectBuilder, possibleSorts map[string]Sort)

func ApplySortStrings

func ApplySortStrings(xs []string, query *squirrel.SelectBuilder, sorts map[string]string)

func Delete

func Delete(db sqlx.Ext, qry squirrel.DeleteBuilder) error

func DeleteWhere

func DeleteWhere(db sqlx.Ext, table string, where interface{}) error

func GetForStruct

func GetForStruct(db sqlx.Queryer, val interface{}, table string, where interface{}) error

func InsertReturningId

func InsertReturningId(db sqlx.Ext, qry squirrel.InsertBuilder, id interface{}) error

func InsertSetMapNoId

func InsertSetMapNoId(db sqlx.Ext, table string, payload interface{}) error

func InsertSetMapReturningId

func InsertSetMapReturningId(db sqlx.Ext, table string, payload interface{}, id interface{}) error

func SelectForStruct

func SelectForStruct(db sqlx.Queryer, slice interface{}, table string, where interface{}) error

func TransformError

func TransformError(err error, cfg map[ErrorConfig]error) error

Transforms the error coming in *if* it is a PG error, based on the configuration.

Usage:

cfg := map[ErrorConfig]error{
   MatchesConstraint("id_fkey"): ErrInvalidId,
}
...
 _, err := db.Exec(....)
 return TransformError(err, cfg)

func Update

func Update(db sqlx.Ext, qry squirrel.UpdateBuilder) error

func UpdateSetMap

func UpdateSetMap(db sqlx.Ext, table string, payload, where interface{}) error

Types

type Accumulator

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

func (*Accumulator) ApplyAnd

func (a *Accumulator) ApplyAnd(sql squirrel.Sqlizer)

func (*Accumulator) ApplyOr

func (a *Accumulator) ApplyOr(sql squirrel.Sqlizer)

func (*Accumulator) ApplyRemainder

func (a *Accumulator) ApplyRemainder(sql squirrel.Sqlizer)

func (*Accumulator) ApplyToQuery

func (a *Accumulator) ApplyToQuery(query *squirrel.SelectBuilder)

func (*Accumulator) GetCondition

func (a *Accumulator) GetCondition() squirrel.Sqlizer

type Byte

type Byte uint8

Postgres Binary requires a specific format when writing and reading. This is used to write and read it properly.

func (*Byte) Scan

func (i *Byte) Scan(value interface{}) error

func (Byte) Value

func (i Byte) Value() (driver.Value, error)

type Direction

type Direction string
const (
	Asc  Direction = "ASC"
	Desc Direction = "DESC"
)

type ErrorConfig

type ErrorConfig interface {
	Test(e *pq.Error) bool
}

type ExtendedSort

type ExtendedSort struct {
	Field          SimpleSort
	SecondarySorts []string
}

func (ExtendedSort) String

func (s ExtendedSort) String(key string) string

type ISearchOperatorConfig

type ISearchOperatorConfig interface {
	Apply(o, rem []operator.Operator, a *Accumulator, prefix string)
	GetKeys() []string
}

configuration for different searches.

type MatchesCode

type MatchesCode pq.ErrorCode

func (MatchesCode) Test

func (c MatchesCode) Test(e *pq.Error) bool

type MatchesConstraint

type MatchesConstraint string

func (MatchesConstraint) Test

func (c MatchesConstraint) Test(e *pq.Error) bool

type MatchesRoutine

type MatchesRoutine string

func (MatchesRoutine) Test

func (c MatchesRoutine) Test(e *pq.Error) bool

type SearchOperatorConfigBase

type SearchOperatorConfigBase struct {
	Keys  []string
	Field string
}

func NewSearchOperatorConfigBase

func NewSearchOperatorConfigBase(field string, keys ...string) SearchOperatorConfigBase

func (SearchOperatorConfigBase) GetKeys

func (c SearchOperatorConfigBase) GetKeys() []string

type SearchOperatorConfigBool

type SearchOperatorConfigBool struct {
	SearchOperatorConfigBase
}

func NewBoolOperator

func NewBoolOperator(field string, keys ...string) SearchOperatorConfigBool

func (SearchOperatorConfigBool) Apply

func (c SearchOperatorConfigBool) Apply(os, rem []operator.Operator, a *Accumulator, prefix string)

type SearchOperatorConfigStringLike

type SearchOperatorConfigStringLike struct {
	SearchOperatorConfigBase
}

func NewStringLikeOperator

func NewStringLikeOperator(field string, keys ...string) SearchOperatorConfigStringLike

func (SearchOperatorConfigStringLike) Apply

func (c SearchOperatorConfigStringLike) Apply(os, rem []operator.Operator, a *Accumulator, prefix string)

func (SearchOperatorConfigStringLike) Sqlizer

type SearchOperatorConfigUUID

type SearchOperatorConfigUUID struct {
	SearchOperatorConfigBase
}

func NewUUIDOperator

func NewUUIDOperator(field string, keys ...string) SearchOperatorConfigUUID

func (SearchOperatorConfigUUID) Apply

func (c SearchOperatorConfigUUID) Apply(os, rem []operator.Operator, a *Accumulator, prefix string)

type SimpleSort

type SimpleSort string

func (SimpleSort) String

func (s SimpleSort) String(key string) string

type Sort

type Sort interface {
	String(string) string
}

Jump to

Keyboard shortcuts

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