Documentation
¶
Index ¶
- func And(filters ...string) string
- func Asc(column string) string
- func Cond(op Op, filters ...string) string
- func Desc(column string) string
- func FmtContains[S string | *string](val S) S
- func FmtEndsWith[S string | *string](val S) S
- func FmtStartsWith[S string | *string](val S) S
- func Having(pred string) string
- func If[T any](pred PredicateFn[T], val T, params *Params, printer PrinterFn) string
- func IfNotNil[T any](val *T, params *Params, printer PrinterFn) string
- func IfNotZero[T comparable](val T, params *Params, printer PrinterFn) string
- func Not(filter string) string
- func Or(filters ...string) string
- func OrderBy(sorts ...string) string
- func Section(sect Sect, cond string) string
- func Sort(column string, sorting Sorting) string
- func Where(pred string) string
- type Op
- type Params
- type PredicateFn
- type PrinterFn
- type Sect
- type Sorting
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func And ¶
And builds a condition concatenating the filters with the AND operator. If the filters are all empty, the returned string is also empty.
func Cond ¶ added in v1.0.0
Cond builds a condition concatenating the filters with the given operator. If the filters are all empty, the returned string is also empty.
func FmtContains ¶ added in v1.0.0
FmtContains maps the parameter with the desired pattern. Skips the mapping if the value is empty or nil
func FmtEndsWith ¶ added in v1.0.0
FmtEndsWith maps the parameter with the desired pattern. Skips the mapping if the value is empty or nil
func FmtStartsWith ¶ added in v1.0.0
FmtStartsWith maps the parameter with the desired pattern. Skips the mapping if the value is empty or nil
func Having ¶
Having builds an HAVING filtering section. If the condition is empty, the returned string is also empty.
func If ¶
func If[T any](pred PredicateFn[T], val T, params *Params, printer PrinterFn) string
If is used to build the query dynamically, based on runtime conditions.
If the predicate is true, the value is pushed in the parameter map and the printed filter is returned. If the predicate is false, the parameter map is untouched, and an empty string is returned.
func IfNotZero ¶ added in v1.0.0
func IfNotZero[T comparable](val T, params *Params, printer PrinterFn) string
IfNotZero is a proxy for If with a predicate that checks if the value is not equal to the zero value of its type
func Or ¶
Or builds a condition concatenating the filters with the OR operator. If the filters are all empty, the returned string is also empty.
func OrderBy ¶
OrderBy builds an ORDER BY section. If the sortings are all empty, the returned string is also empty.
func Section ¶ added in v1.0.0
Section builds a filtering section. If the condition is empty, the returned string is also empty.
Types ¶
type PredicateFn ¶ added in v1.0.0
Predicate is a callback that validates a condition on a value
type PrinterFn ¶ added in v1.0.0
PrinterFn is a callback that applies a parameter to the given statement (usually a filter)
func Gt ¶ added in v1.0.0
Gt produces a PrinterFn that checks if the target is greater than the given parameter
func Gte ¶ added in v1.0.0
Gte produces a PrinterFn that checks if the target is greater or equal the given parameter
func ILike ¶ added in v1.0.0
ILike produces a PrinterFn that checks if the target text respects the given pattern, ignoring the casing
func In ¶
In produces a PrinterFn that checks if the target is contained in the given parameter slice
func Like ¶ added in v1.0.0
Like produces a PrinterFn that checks if the target text respects the given pattern