Documentation ¶
Index ¶
- func Append[T any](u *sql.UpdateBuilder, column string, elems []T, opts ...Option)
- func HasKey(column string, opts ...Option) *sql.Predicate
- func LenEQ(column string, size int, opts ...Option) *sql.Predicate
- func LenGT(column string, size int, opts ...Option) *sql.Predicate
- func LenGTE(column string, size int, opts ...Option) *sql.Predicate
- func LenLT(column string, size int, opts ...Option) *sql.Predicate
- func LenLTE(column string, size int, opts ...Option) *sql.Predicate
- func LenNEQ(column string, size int, opts ...Option) *sql.Predicate
- func LenPath(column string, opts ...Option) sql.Querier
- func OrderLen(column string, opts ...Option) func(*sql.Selector)
- func OrderLenDesc(column string, opts ...Option) func(*sql.Selector)
- func OrderValue(column string, opts ...Option) func(*sql.Selector)
- func OrderValueDesc(column string, opts ...Option) func(*sql.Selector)
- func ParsePath(dotpath string) ([]string, error)
- func StringContains(column string, sub string, opts ...Option) *sql.Predicate
- func StringHasPrefix(column string, prefix string, opts ...Option) *sql.Predicate
- func StringHasSuffix(column string, suffix string, opts ...Option) *sql.Predicate
- func ValueContains(column string, arg any, opts ...Option) *sql.Predicate
- func ValueEQ(column string, arg any, opts ...Option) *sql.Predicate
- func ValueGT(column string, arg any, opts ...Option) *sql.Predicate
- func ValueGTE(column string, arg any, opts ...Option) *sql.Predicate
- func ValueIn(column string, args []any, opts ...Option) *sql.Predicate
- func ValueIsNotNull(column string, opts ...Option) *sql.Predicate
- func ValueIsNull(column string, opts ...Option) *sql.Predicate
- func ValueLT(column string, arg any, opts ...Option) *sql.Predicate
- func ValueLTE(column string, arg any, opts ...Option) *sql.Predicate
- func ValueNEQ(column string, arg any, opts ...Option) *sql.Predicate
- func ValueNotIn(column string, args []any, opts ...Option) *sql.Predicate
- func ValuePath(column string, opts ...Option) sql.Querier
- type Option
- type PathOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
func Append[T any](u *sql.UpdateBuilder, column string, elems []T, opts ...Option)
Append writes to the given SQL builder the SQL command for appending JSON values into the array, optionally defined as a key. Note, the generated SQL will use the Go semantics, the JSON column/key will be set to the given Array in case it is `null` or NULL. For example:
Append(u, column, []string{"a", "b"}) UPDATE "t" SET "c" = CASE WHEN ("c" IS NULL OR "c" = 'null'::jsonb) THEN $1 ELSE "c" || $2 END Append(u, column, []any{"a", 1}, sqljson.Path("a")) UPDATE "t" SET "c" = CASE WHEN (("c"->'a')::jsonb IS NULL OR ("c"->'a')::jsonb = 'null'::jsonb) THEN jsonb_set("c", '{a}', $1, true) ELSE jsonb_set("c", '{a}', "c"->'a' || $2, true) END
func HasKey ¶
HasKey return a predicate for checking that a JSON key exists and not NULL.
sqljson.HasKey("column", sql.DotPath("a.b[2].c"))
func LenEQ ¶
LenEQ return a predicate for checking that an array length of a JSON (returned by the path) is equal to the given argument.
sqljson.LenEQ("a", 1, sqljson.Path("b"))
func LenGT ¶
LenGT return a predicate for checking that an array length of a JSON (returned by the path) is greater than the given argument.
sqljson.LenGT("a", 1, sqljson.Path("b"))
func LenGTE ¶
LenGTE return a predicate for checking that an array length of a JSON (returned by the path) is greater than or equal to the given argument.
sqljson.LenGTE("a", 1, sqljson.Path("b"))
func LenLT ¶
LenLT return a predicate for checking that an array length of a JSON (returned by the path) is less than the given argument.
sqljson.LenLT("a", 1, sqljson.Path("b"))
func LenLTE ¶
LenLTE return a predicate for checking that an array length of a JSON (returned by the path) is less than or equal to the given argument.
sqljson.LenLTE("a", 1, sqljson.Path("b"))
func LenNEQ ¶
LenNEQ return a predicate for checking that an array length of a JSON (returned by the path) is not equal to the given argument.
sqljson.LenEQ("a", 1, sqljson.Path("b"))
func LenPath ¶
LenPath returns an SQL expression for getting the length of a JSON value (returned by the path).
func OrderLen ¶
OrderLen returns a custom predicate function (as defined in the doc), that sets the result order by the length of the given JSON value.
func OrderLenDesc ¶
OrderLenDesc returns a custom predicate function (as defined in the doc), that sets the result order by the length of the given JSON value, but in descending order.
func OrderValue ¶
OrderValue returns a custom predicate function (as defined in the doc), that sets the result order by the given JSON value.
func OrderValueDesc ¶
OrderValueDesc returns a custom predicate function (as defined in the doc), that sets the result order by the given JSON value, but in descending order.
func ParsePath ¶
ParsePath parses the "dotpath" for the DotPath option.
"a.b" => ["a", "b"] "a[1][2]" => ["a", "[1]", "[2]"] "a.\"b.c\" => ["a", "\"b.c\""]
func StringContains ¶
StringContains return a predicate for checking that a JSON string value (returned by the path) contains the given substring
func StringHasPrefix ¶
StringHasPrefix return a predicate for checking that a JSON string value (returned by the path) has the given substring as prefix
func StringHasSuffix ¶
StringHasSuffix return a predicate for checking that a JSON string value (returned by the path) has the given substring as suffix
func ValueContains ¶
ValueContains return a predicate for checking that a JSON value (returned by the path) contains the given argument.
sqljson.ValueContains("a", 1, sqljson.Path("b"))
func ValueEQ ¶
ValueEQ return a predicate for checking that a JSON value (returned by the path) is equal to the given argument.
sqljson.ValueEQ("a", 1, sqljson.Path("b"))
func ValueGT ¶
ValueGT return a predicate for checking that a JSON value (returned by the path) is greater than the given argument.
sqljson.ValueGT("a", 1, sqljson.Path("b"))
func ValueGTE ¶
ValueGTE return a predicate for checking that a JSON value (returned by the path) is greater than or equal to the given argument.
sqljson.ValueGTE("a", 1, sqljson.Path("b"))
func ValueIn ¶
ValueIn return a predicate for checking that a JSON value (returned by the path) is IN the given arguments.
sqljson.ValueIn("a", []any{1, 2, 3}, sqljson.Path("b"))
func ValueIsNotNull ¶
ValueIsNotNull return a predicate for checking that a JSON value (returned by the path) is not null literal (JSON "null").
sqljson.ValueIsNotNull("a", sqljson.Path("b"))
func ValueIsNull ¶
ValueIsNull return a predicate for checking that a JSON value (returned by the path) is a null literal (JSON "null").
In order to check if the column is NULL (database NULL), or if the JSON key exists, use sql.IsNull or sqljson.HasKey.
sqljson.ValueIsNull("a", sqljson.Path("b"))
func ValueLT ¶
ValueLT return a predicate for checking that a JSON value (returned by the path) is less than the given argument.
sqljson.ValueLT("a", 1, sqljson.Path("b"))
func ValueLTE ¶
ValueLTE return a predicate for checking that a JSON value (returned by the path) is less than or equal to the given argument.
sqljson.ValueLTE("a", 1, sqljson.Path("b"))
func ValueNEQ ¶
ValueNEQ return a predicate for checking that a JSON value (returned by the path) is not equal to the given argument.
sqljson.ValueNEQ("a", 1, sqljson.Path("b"))
func ValueNotIn ¶
ValueNotIn return a predicate for checking that a JSON value (returned by the path) is NOT IN the given arguments.
sqljson.ValueNotIn("a", []any{1, 2, 3}, sqljson.Path("b"))
Types ¶
type Option ¶
type Option func(*PathOptions)
Option allows for calling database JSON paths with functional options.
func Cast ¶
Cast indicates that the result value should be cast to the given type.
ValuePath(b, "column", Path("a", "b", "[1]", "c"), Cast("int"))
func DotPath ¶
DotPath is similar to Path, but accepts string with dot format.
ValuePath(b, "column", DotPath("a.b.c")) ValuePath(b, "column", DotPath("a.b[2].c"))
Note that DotPath is ignored if the input is invalid.