Documentation
¶
Overview ¶
Package arrayop holds the PostgreSQL array predicates: containment, contained-by, overlap and the single-bind "= ANY" membership test. Each binds its values as one array parameter, so the bind count does not grow with the list. Other dialects have no array columns, so the build fails with momo.ErrUnsupported there; use momo's In on SQLite and MySQL.
The package builds on the exported extension API of the root package (PredicateFunc, Builder.ArgFor, Builder.RenderSensitive, Builder.Unsupported and FlagsOf) and is the reference for writing a feature package outside the root.
Example ¶
Contains binds the values as one array parameter, however many there are. Other dialects have no array columns and fail the build with ErrUnsupported.
package main
import (
"errors"
"fmt"
"github.com/azrtydxb/momo"
"github.com/azrtydxb/momo/arrayop"
"github.com/azrtydxb/momo/dialect"
)
func main() {
tags := momo.NewColumn[[]string]("docs", "tags", 0)
pred := arrayop.Contains(tags, "go", "sql")
pg := momo.NewBuilder(dialect.For(dialect.Postgres))
pred.AppendSQL(pg)
fmt.Println(pg.String(), pg.Args())
lite := momo.NewBuilder(dialect.For(dialect.SQLite))
pred.AppendSQL(lite)
fmt.Println(errors.Is(lite.Err(), momo.ErrUnsupported))
}
Output: "docs"."tags" @> $1 [[go sql]] true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyOf ¶
func AnyOf[T any](col momo.Expression[T], vals ...T) momo.Predicate
AnyOf is true when the scalar column equals one of vals (col = ANY($n)), with the slice bound as a single array parameter. Unlike In it uses one bind however many values there are, and an empty list is false. Other dialects fail the build with ErrUnsupported; use In there.
Example ¶
AnyOf tests a scalar column against a list with a single bind, so the statement text does not change with the length of the list.
package main
import (
"fmt"
"github.com/azrtydxb/momo"
"github.com/azrtydxb/momo/arrayop"
"github.com/azrtydxb/momo/dialect"
)
func main() {
title := momo.NewColumn[string]("docs", "title", 0)
b := momo.NewBuilder(dialect.For(dialect.Postgres))
arrayop.AnyOf(title, "a", "b", "c").AppendSQL(b)
fmt.Println(b.String(), b.Args())
}
Output: "docs"."title" = ANY($1) [[a b c]]
func ContainedBy ¶
func ContainedBy[T any](col momo.Expression[[]T], vals ...T) momo.Predicate
ContainedBy is true when every element of the array column is among vals (PostgreSQL <@). Other dialects fail the build with ErrUnsupported.
func Contains ¶
func Contains[T any](col momo.Expression[[]T], vals ...T) momo.Predicate
Contains is true when the array column contains every one of vals (PostgreSQL @>). The slice is bound as one array parameter. With no values it is true for every non-NULL array. Other dialects fail the build with ErrUnsupported.
Types ¶
This section is empty.