dbutil

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: 10 Imported by: 2

Documentation

Index

Constants

View Source
const SelectSetTagName = "select-sets"
View Source
const SelectTagName = "select"
View Source
const SetMapTagName = "setmap"

Variables

View Source
var (
	ErrNoSelects = errors.New("no selects")
)

Functions

func ColumnNameFromDbTag

func ColumnNameFromDbTag(f reflect.StructField) string

func DebugQuery

func DebugQuery(query squirrel.Sqlizer)

func DebugQueryPieces

func DebugQueryPieces(sql string, args []interface{}, err error)

func DefaultCoalescer

func DefaultCoalescer(t reflect.Type, s *SelectTags) string

func Exists

func Exists(db sqlx.Queryer, qry squirrel.SelectBuilder) (bool, error)

func Get

func Get(db sqlx.Queryer, val interface{}, qry squirrel.SelectBuilder) error

func GetColumnsByTag

func GetColumnsByTag(val interface{}, prefix string, filterFields ...string) map[string]string

func GetColumnsByTagExcl

func GetColumnsByTagExcl(val interface{}, prefix string, filterFields ...string) map[string]string

func GetColumnsForSet

func GetColumnsForSet(set string, val interface{}, prefix string, filterFields ...string) []string

func GetColumnsForSetExcl

func GetColumnsForSetExcl(set string, val interface{}, prefix string, filterFields ...string) []string

func GetColumnsList

func GetColumnsList(val interface{}, prefix string, filterFields ...string) []string

func GetColumnsListExcl

func GetColumnsListExcl(val interface{}, prefix string, filterFields ...string) []string

func IterateColumnNames

func IterateColumnNames(set string, val interface{}, it SelectIterator, invert bool, filterFields ...string)

func IteratePgFields

func IteratePgFields(val interface{}, isInsert bool, it SetMapIterator)

func MkJoinStr

func MkJoinStr(t1, c1, t2, c2 string) string

func QuickExecTx

func QuickExecTx(tx sqlx.Execer, queries []string, arg ...interface{}) error

func QuickRows

func QuickRows(db sqlx.Queryer, qry squirrel.SelectBuilder, fn RowHandler) error

func RunMulti

func RunMulti(tx *sqlx.Tx, fns []TxFunc) error

func RunMultiExt

func RunMultiExt(ext sqlx.Ext, fns []ExtFunc) error

func Select

func Select(db sqlx.Queryer, slice interface{}, qry squirrel.SelectBuilder) error

func SetCoalescer

func SetCoalescer(c Coalescer)

func SetMap

func SetMap(val interface{}, isInsert bool) map[string]interface{}

func TxNow

func TxNow(db *sqlx.DB, fn TxFunc) error

func TxNowMulti

func TxNowMulti(db *sqlx.DB, fn []TxFunc) error

func Union

func Union(selects ...squirrel.SelectBuilder) (squirrel.SelectBuilder, error)

Allows for unions queries. Created another select query using suffixes. Where and Join queries should not be made after calling this query, as those queries will only affect the *first* query on the list.

Types

type Coalescer

type Coalescer func(reflect.Type, *SelectTags) string
var CoalesceFromType Coalescer = DefaultCoalescer

type ExtFunc

type ExtFunc func(tx sqlx.Ext) error

type ILikeAnd

type ILikeAnd map[string]interface{}

func (ILikeAnd) ToSql

func (il ILikeAnd) ToSql() (string, []interface{}, error)

type ILikeOr

type ILikeOr map[string]interface{}

func (ILikeOr) ToSql

func (il ILikeOr) ToSql() (string, []interface{}, error)

type InvalidUnionError

type InvalidUnionError struct {
	BaseError error
	Index     int
}

func (InvalidUnionError) Error

func (e InvalidUnionError) Error() string

type RowHandler

type RowHandler func(*sqlx.Rows) error

type SelectIterator

type SelectIterator func(name string, f reflect.StructField, t *SelectTags)

type SelectTags

type SelectTags struct {
	Coalesce bool
	Ignore   bool
	UUID     bool
	Sets     []string
}

func (*SelectTags) Apply

func (t *SelectTags) Apply(
	column string,
	prefix string,
	f reflect.Type,
) string

func (*SelectTags) ContainsSet

func (t *SelectTags) ContainsSet(set string) bool

func (*SelectTags) Parse

func (t *SelectTags) Parse(str string)

func (*SelectTags) ParseSets

func (t *SelectTags) ParseSets(str string)

type SetMapIterator

type SetMapIterator func(string, interface{})

type SetMapTags

type SetMapTags struct {
	OmitEmpty  bool
	OmitInsert bool
	Ignore     bool
}

func ParseSetMapTags

func ParseSetMapTags(str string) *SetMapTags

func (*SetMapTags) Parse

func (t *SetMapTags) Parse(str string)

type TxFunc

type TxFunc func(tx *sqlx.Tx) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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