jsonpath

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MethodTypeStrings = [...]string{
	SizeMethod:    "size",
	TypeMethod:    "type",
	AbsMethod:     "abs",
	FloorMethod:   "floor",
	CeilingMethod: "ceiling",
}
View Source
var OperationTypeStrings = [...]string{
	OpCompEqual:        "==",
	OpCompNotEqual:     "!=",
	OpCompLess:         "<",
	OpCompLessEqual:    "<=",
	OpCompGreater:      ">",
	OpCompGreaterEqual: ">=",
	OpLogicalAnd:       "&&",
	OpLogicalOr:        "||",
	OpLogicalNot:       "!",
	OpAdd:              "+",
	OpSub:              "-",
	OpMult:             "*",
	OpDiv:              "/",
	OpMod:              "%",
	OpLikeRegex:        "like_regex",
	OpPlus:             "+",
	OpMinus:            "-",
	OpExists:           "exists",
	OpIsUnknown:        "is unknown",
	OpStartsWith:       "starts with",
}

Functions

func RegexFlagsToGoFlags

func RegexFlagsToGoFlags(flags string) (syntax.Flags, error)

RegexFlagsToGoFlags converts a string of flags from `like_regex` to syntax.Flags, to match the flags provided by Postgres' `like_regex` flag interface.

The following flags are defined in Postgres: - i: case-insensitive - s: dot matches newline - m: ^ and $ match at newlines - x: ignore whitespace in pattern (this flag is defined, but not accepted) - q: no special characters

Types

type AnyKey

type AnyKey struct{}

func (AnyKey) ToString

func (a AnyKey) ToString(sb *strings.Builder, inKey, _ bool)

func (AnyKey) Validate

func (a AnyKey) Validate(nestingLevel int, insideArraySubscript bool) error

type ArrayIndexRange

type ArrayIndexRange struct {
	Start Path
	End   Path
}

func (ArrayIndexRange) ToString

func (a ArrayIndexRange) ToString(sb *strings.Builder, _, _ bool)

func (ArrayIndexRange) Validate

func (a ArrayIndexRange) Validate(nestingLevel int, insideArraySubscript bool) error

type ArrayList

type ArrayList []Path

func (ArrayList) ToString

func (a ArrayList) ToString(sb *strings.Builder, _, _ bool)

func (ArrayList) Validate

func (a ArrayList) Validate(nestingLevel int, insideArraySubscript bool) error

type Current

type Current struct{}

func (Current) ToString

func (c Current) ToString(sb *strings.Builder, _, _ bool)

func (Current) Validate

func (c Current) Validate(nestingLevel int, insideArraySubscript bool) error

type Filter

type Filter struct {
	Condition Path
}

func (Filter) ToString

func (f Filter) ToString(sb *strings.Builder, _, _ bool)

func (Filter) Validate

func (f Filter) Validate(nestingLevel int, insideArraySubscript bool) error

type Jsonpath

type Jsonpath struct {
	Strict bool
	Path   Path
}

func (Jsonpath) String

func (j Jsonpath) String() string

func (Jsonpath) Validate

func (j Jsonpath) Validate() error

Validate walks the Jsonpath AST. It returns an error if the AST is invalid (last not in array subscripts, @ in root expressions).

type Key

type Key string

func (Key) ToString

func (k Key) ToString(sb *strings.Builder, inKey, _ bool)

func (Key) Validate

func (k Key) Validate(nestingLevel int, insideArraySubscript bool) error

type Last

type Last struct{}

func (Last) ToString

func (l Last) ToString(sb *strings.Builder, _, _ bool)

func (Last) Validate

func (l Last) Validate(nestingLevel int, insideArraySubscript bool) error

type Method

type Method struct {
	Type MethodType
}

func (Method) ToString

func (m Method) ToString(sb *strings.Builder, _, _ bool)

func (Method) Validate

func (m Method) Validate(nestingLevel int, insideArraySubscript bool) error

type MethodType

type MethodType int
const (
	InvalidMethod MethodType = iota
	SizeMethod
	TypeMethod
	AbsMethod
	FloorMethod
	CeilingMethod
)

type Operation

type Operation struct {
	Type  OperationType
	Left  Path
	Right Path
}

func (Operation) ToString

func (o Operation) ToString(sb *strings.Builder, _, printBrackets bool)

func (Operation) Validate

func (o Operation) Validate(nestingLevel int, insideArraySubscript bool) error

type OperationType

type OperationType int
const (
	OpInvalid OperationType = iota
	OpCompEqual
	OpCompNotEqual
	OpCompLess
	OpCompLessEqual
	OpCompGreater
	OpCompGreaterEqual
	OpLogicalAnd
	OpLogicalOr
	OpLogicalNot
	OpAdd
	OpSub
	OpMult
	OpDiv
	OpMod
	OpLikeRegex
	OpPlus
	OpMinus
	OpExists
	OpIsUnknown
	OpStartsWith
)

type Path

type Path interface {
	// ToString appends the string representation of the path to the given
	// strings.Builder. This implementation matches
	// postgres/src/backend/utils/adt/jsonpath.c:printJsonPathItem().
	ToString(sb *strings.Builder, inKey, printBrackets bool)

	// Validate returns an error if there is a semantic error in the path, and
	// collects all variable names in a map with a strictly increasing index,
	// indicating the order of their first appearance. Leaf nodes should generally
	// return nil.
	Validate(nestingLevel int, insideArraySubscript bool) error
}

type Paths

type Paths []Path

func (Paths) ToString

func (p Paths) ToString(sb *strings.Builder, _, _ bool)

func (Paths) Validate

func (p Paths) Validate(nestingLevel int, insideArraySubscript bool) error

type Regex

type Regex struct {
	Regex string
	Flags syntax.Flags
}

func (Regex) Pattern

func (r Regex) Pattern() (string, error)

Pattern implements the tree.RegexpCacheKey interface.

func (Regex) ToString

func (r Regex) ToString(sb *strings.Builder, _, _ bool)

func (Regex) Validate

func (r Regex) Validate(nestingLevel int, insideArraySubscript bool) error

type Root

type Root struct{}

func (Root) ToString

func (r Root) ToString(sb *strings.Builder, _, _ bool)

func (Root) Validate

func (r Root) Validate(nestingLevel int, insideArraySubscript bool) error

type Scalar

type Scalar struct {
	Type     ScalarType
	Value    json.JSON
	Variable string
}

func (Scalar) ToString

func (s Scalar) ToString(sb *strings.Builder, _, _ bool)

func (Scalar) Validate

func (s Scalar) Validate(nestingLevel int, insideArraySubscript bool) error

type ScalarType

type ScalarType int
const (
	ScalarInt ScalarType = iota
	ScalarFloat
	ScalarString
	ScalarBool
	ScalarNull
	ScalarVariable
)

type Wildcard

type Wildcard struct{}

func (Wildcard) ToString

func (w Wildcard) ToString(sb *strings.Builder, _, _ bool)

func (Wildcard) Validate

func (w Wildcard) Validate(nestingLevel int, insideArraySubscript bool) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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