Documentation ¶
Index ¶
- Variables
- func NoOp() (string, []driver.Value, error)
- func PgPrepare(query string, args []driver.Value) string
- func TableColumn[M Model](column string) string
- func TableColumnErr[M Model](column string) (string, error)
- func TableColumns[M Model]() []string
- func TableName[M Model]() string
- type Condition
- type JoinType
- type Model
- type SortingOrder
- type SqldFn
- func AllWildcard() SqldFn
- func And(ops ...SqldFn) SqldFn
- func As(op SqldFn, aliasName string) SqldFn
- func Asc(columnExpr string) SqldFn
- func Coalesce(op SqldFn, fallback string) SqldFn
- func ColumnEq(firstColumn string, secondColumn string) SqldFn
- func Columns(columns ...string) SqldFn
- func Count(op SqldFn) SqldFn
- func Desc(columnExpr string) SqldFn
- func Eq[T driver.Value](columnExpr string, val *T) SqldFn
- func From(op SqldFn) SqldFn
- func GroupBy(ops ...SqldFn) SqldFn
- func Having(ops ...SqldFn) SqldFn
- func If(pred func() bool, op SqldFn) SqldFn
- func IfElse(pred func() bool, trueFn SqldFn, falseFn SqldFn) SqldFn
- func IfEmpty[T driver.Value](vals []T, op SqldFn) SqldFn
- func IfEmptyElse[T driver.Value](vals []T, trueFn SqldFn, falseFn SqldFn) SqldFn
- func IfNil[T driver.Value](val *T, op SqldFn) SqldFn
- func IfNilElse[T driver.Value](val *T, trueFn SqldFn, falseFn SqldFn) SqldFn
- func IfNotEmpty[T driver.Value](vals []T, op SqldFn) SqldFn
- func IfNotEmptyElse[T driver.Value](vals []T, trueFn SqldFn, falseFn SqldFn) SqldFn
- func IfNotNil[T driver.Value](val *T, op SqldFn) SqldFn
- func IfNotNilElse[T driver.Value](val *T, trueFn SqldFn, falseFn SqldFn) SqldFn
- func IfStringEmpty(val string, op SqldFn) SqldFn
- func IfStringEmptyElse(val string, trueFn, falseFn SqldFn) SqldFn
- func IfStringNotEmpty(val string, op SqldFn) SqldFn
- func IfStringNotEmptyElse(val string, trueFn, falseFn SqldFn) SqldFn
- func In[T driver.Value](columnExpr string, vals *[]T) SqldFn
- func Join(joinType JoinType, subject SqldFn, op SqldFn) SqldFn
- func Just(s string) SqldFn
- func LeftJoin(subject SqldFn, op SqldFn) SqldFn
- func Limit(count *uint) SqldFn
- func New(ops ...SqldFn) SqldFn
- func Not(op SqldFn) SqldFn
- func Null(columnExpr string) SqldFn
- func Offset(skip *uint) SqldFn
- func Or(ops ...SqldFn) SqldFn
- func OrderBy(ops ...SqldFn) SqldFn
- func PgPrepareOp(op SqldFn) SqldFn
- func RightJoin(subject SqldFn, op SqldFn) SqldFn
- func Select(ops ...SqldFn) SqldFn
- func Sort(order SortingOrder, columnExpr string) SqldFn
- func SubQuery(op SqldFn, aliasName string) SqldFn
- func Where(ops ...SqldFn) SqldFn
Constants ¶
This section is empty.
Variables ¶
var ErrArgNotSlice = errors.New("argument is not a slice")
var ErrEmptySlice = errors.New("slice is empty")
var ErrNilColumnExpr = errors.New("column expression is nil")
var ErrNilVal = errors.New("value is nil")
var ErrNoColumns = errors.New("no columns in statement")
var ErrNoOps = errors.New("operations slice is empty")
Functions ¶
func TableColumn ¶ added in v0.3.1
TableColumn returns a combination of `Model.TableName()` and the provided column. Panics if the column is not present in the model
func TableColumnErr ¶ added in v0.3.1
TableColumnErr returns a combination of `Model.TableName()` and the provided column. Returns error if the column is not present in the model
func TableColumns ¶ added in v0.3.1
TableColumns extracts a list of columns from a `Model`, using sqlx `db` tags and falling back on field names
Types ¶
type JoinType ¶ added in v0.2.0
type JoinType string
const ( LEFT_JOIN JoinType = "LEFT" RIGHT_JOIN JoinType = "RIGHT" INNER_JOIN JoinType = "INNER" CROSS_JOIN JoinType = "CROSS" FULL_JOIN JoinType = "FULL" LEFT_OUTER_JOIN JoinType = "LEFT OUTER" RIGHT_OUTER_JOIN JoinType = "RIGHT OUTER" INNER_OUTER_JOIN JoinType = "INNER OUTER" CROSS_OUTER_JOIN JoinType = "CROSS OUTER" FULL_OUTER_JOIN JoinType = "FULL OUTER" )
type SortingOrder ¶ added in v0.5.3
type SortingOrder string
const ( ASC SortingOrder = "ASC" DESC SortingOrder = "DESC" )
type SqldFn ¶
SqldFn is the type describing all callbacks used in the library.
func AllWildcard ¶ added in v0.5.0
func AllWildcard() SqldFn
AllWildcard builds a callback that just returns a "*" string
func And ¶
And builds a callback combining all the operators with AND conditions.
sqld.And( sqld.IfNotNil(filters.Name, sqld.Eq("name", filters.Name), ), sqld.IfNotEmpty(filters.Pizzas, sqld.In("pizzas", filters.Pizzas), ), )
func ColumnEq ¶ added in v0.2.1
ColumnEq builds a callback that returns a comparison statement between two columns
func Columns ¶ added in v0.2.0
Columns builds a callback that returns a list of columns, comma-separated
func Count ¶ added in v0.5.0
Count builds a callback that returns a COUNT function with the given argument
func Eq ¶
Eq builds a callback that compares a column with the provided value.
sqld.Eq("name", filters.Name)
func From ¶ added in v0.2.0
From builds a callback that just returns a FROM statement with the provided table
func Having ¶
Having builds a callback combining all the operators in a HAVING statement.
sqld.Having( sqld.And( sqld.IfNotNil(filters.Name, sqld.Eq("name", filters.Name), ), sqld.IfNotEmpty(filters.Pizzas, sqld.In("pizzas", filters.Pizzas), ), ), )
func IfNotEmptyElse ¶
func IfStringEmpty ¶ added in v0.6.0
func IfStringEmptyElse ¶ added in v0.6.0
func IfStringNotEmpty ¶ added in v0.6.0
func IfStringNotEmptyElse ¶ added in v0.6.0
func In ¶
In builds a callback that checks if a column value is contained in the provided slice of values.
sqld.In("pizzas", filters.Pizzas)
func Join ¶ added in v0.2.0
Join builds a callback that returns a JOIN statement of the provided type with the desired subject, with a condition callback
func New ¶
New builds a `SqldFn` callback combining the provided operators.
Example usage:
const query := sqld.New( sqld.Select( sqld.Columns( "name", "pizzas", ), ), sqld.From(sqld.Just("Table")), sqld.Where( sqld.And( sqld.IfNotNil(filters.Name, sqld.Eq("name", filters.Name), ), sqld.IfNotEmpty(filters.Pizzas, sqld.In("pizzas", filters.Pizzas), ), ), ), sqld.OrderBy(sqld.Desc(filters.OrderBy)), )
func Or ¶
Or builds a callback combining all the operators with OR conditions.
sqld.Or( sqld.IfNotNil(filters.Name, sqld.Eq("name", filters.Name), ), sqld.IfNotEmpty(filters.Pizzas, sqld.In("pizzas", filters.Pizzas), ), )
func OrderBy ¶
OrderBy builds a callback combining all the operators in a ORDER BY statement.
sqld.OrderBy( sqld.IfNotNil(filters.OrderBy, sqld.Desc(filters.OrderBy), ), )
func PgPrepareOp ¶ added in v0.8.0
PgPrepareOp applies PgPrepare() to the resulting query in the operator. Use this as the last operator!
func Select ¶ added in v0.1.0
Select builds a callback that returns a SELECT statement with a concatenation of the provided operators.
func Sort ¶ added in v0.5.4
func Sort(order SortingOrder, columnExpr string) SqldFn
Sort builds a callback used to specify the sorting in `OrderBy()`.