Documentation
¶
Overview ¶
Package jsonpath renders the "column->a->b[0]" selector syntax into the JSON path literals and operands each database expects. The functions are pure string builders; quoting here is what keeps a path from breaking out of its SQL literal.
Index ¶
- func Encode(v any) (string, error)
- func IsContainer(v any) bool
- func IsSelector(s string) bool
- func LastSegment(s string) string
- func ParseIndexSegment(last string) (key string, index int, ok bool)
- func Path(v string) string
- func PgAttributes(path []string, quote string) []string
- func SplitKey(key string) (column string, path []string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsContainer ¶
IsContainer reports values that encode as a JSON object or array (maps, structs, slices other than []byte), as opposed to a scalar.
func IsSelector ¶
IsSelector reports whether s uses the "->" JSON path syntax.
func LastSegment ¶
LastSegment returns what follows the last "." ("tbl.col" -> "col").
func ParseIndexSegment ¶
ParseIndexSegment recognises a path's last segment as an array index, either a bare integer ("2") or a keyed one ("tags[-2]"). key is what precedes the index ("" for a bare integer).
func Path ¶
Path renders a MySQL/SQLite JSON path literal for "a->b[0]": '$."a"."b"[0]'. Single quotes are doubled (and backslashes before them dropped) so the literal cannot be escaped.
func PgAttributes ¶
PgAttributes turns path segments into Postgres path operands, expanding "key[0][1]" and quoting non-integers with quote ("'" for -> operands, `"` inside a '{...}' path).
Types ¶
This section is empty.