sqljson

package
v0.11.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2022 License: Apache-2.0 Imports: 6 Imported by: 111

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasKey

func HasKey(column string, opts ...Option) *sql.Predicate

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

func LenEQ(column string, size int, opts ...Option) *sql.Predicate

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

func LenGT(column string, size int, opts ...Option) *sql.Predicate

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

func LenGTE(column string, size int, opts ...Option) *sql.Predicate

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

func LenLT(column string, size int, opts ...Option) *sql.Predicate

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

func LenLTE(column string, size int, opts ...Option) *sql.Predicate

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

func LenNEQ(column string, size int, opts ...Option) *sql.Predicate

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

func LenPath(b *sql.Builder, column string, opts ...Option)

LenPath writes to the given SQL builder the JSON path for getting the length of a given JSON path.

sqljson.LenPath(b, Path("a", "b", "[1]", "c"))

func ParsePath

func ParsePath(dotpath string) ([]string, error)

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 added in v0.10.0

func StringContains(column string, sub string, opts ...Option) *sql.Predicate

StringContains return a predicate for checking that a JSON string value (returned by the path) contains the given substring

func StringHasPrefix added in v0.10.0

func StringHasPrefix(column string, prefix string, opts ...Option) *sql.Predicate

StringHasPrefix return a predicate for checking that a JSON string value (returned by the path) has the given substring as prefix

func StringHasSuffix added in v0.10.0

func StringHasSuffix(column string, suffix string, opts ...Option) *sql.Predicate

StringHasSuffix return a predicate for checking that a JSON string value (returned by the path) has the given substring as suffix

func ValueContains

func ValueContains(column string, arg interface{}, opts ...Option) *sql.Predicate

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

func ValueEQ(column string, arg interface{}, opts ...Option) *sql.Predicate

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

func ValueGT(column string, arg interface{}, opts ...Option) *sql.Predicate

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

func ValueGTE(column string, arg interface{}, opts ...Option) *sql.Predicate

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 ValueIsNull added in v0.10.0

func ValueIsNull(column string, opts ...Option) *sql.Predicate

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

func ValueLT(column string, arg interface{}, opts ...Option) *sql.Predicate

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

func ValueLTE(column string, arg interface{}, opts ...Option) *sql.Predicate

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

func ValueNEQ(column string, arg interface{}, opts ...Option) *sql.Predicate

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 ValuePath

func ValuePath(b *sql.Builder, column string, opts ...Option)

ValuePath writes to the given SQL builder the JSON path for getting the value of a given JSON path.

sqljson.ValuePath(b, Path("a", "b", "[1]", "c"), Cast("int"))

Types

type Option

type Option func(*PathOptions)

Option allows for calling database JSON paths with functional options.

func Cast

func Cast(typ string) Option

Cast indicates that the result value should be casted to the given type.

ValuePath(b, "column", Path("a", "b", "[1]", "c"), Cast("int"))

func DotPath

func DotPath(dotpath string) Option

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.

func Path

func Path(path ...string) Option

Path sets the path to the JSON value of a column.

ValuePath(b, "column", Path("a", "b", "[1]", "c"))

func Unquote

func Unquote(unquote bool) Option

Unquote indicates that the result value should be unquoted.

ValuePath(b, "column", Path("a", "b", "[1]", "c"), Unquote(true))

type PathOptions

type PathOptions struct {
	Ident   string
	Path    []string
	Cast    string
	Unquote bool
}

PathOptions holds the options for accessing a JSON value from an identifier.

Jump to

Keyboard shortcuts

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