sqljson

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

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 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 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