expr

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package expr implements DynamoDB's expression languages — condition, filter, and key-condition expressions (one shared grammar), update expressions, and projection expressions — with a real lexer and recursive-descent parsers. Expressions carry no literals: every value arrives as a :ref resolved against ExpressionAttributeValues, and #refs substitute attribute names.

The evaluators run on item.Item values. Unused name/value references are detected (ValidationException, like real DynamoDB) via the Used sets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cond

type Cond struct {
	// contains filtered or unexported fields
}

Cond is a parsed condition/filter/key-condition expression.

func ParseCondition

func ParseCondition(src string, env *Env) (*Cond, *awshttp.APIError)

ParseCondition parses a condition or filter expression against env.

func (*Cond) Eval

func (c *Cond) Eval(it item.Item) (bool, *awshttp.APIError)

Eval evaluates the condition against an item.

type Env

type Env struct {
	Names  map[string]string     // "#n" -> attribute name
	Values map[string]item.Value // ":v" -> value
	// contains filtered or unexported fields
}

Env carries the request's name/value substitutions and tracks which were actually referenced, so unused ones can be rejected like real DynamoDB.

func NewEnv

func NewEnv(names map[string]string, values map[string]item.Value) *Env

NewEnv builds an evaluation environment.

func (*Env) CheckAllUsed

func (e *Env) CheckAllUsed() *awshttp.APIError

CheckAllUsed errors if any provided substitution went unreferenced — the SDK-observable ValidationException real DynamoDB raises.

type KeyCondition

type KeyCondition struct {
	PKName  string
	PKValue item.Value

	SKName   string     // empty when no sort-key condition
	SKOp     string     // "=", "<", "<=", ">", ">=", "BETWEEN", "begins_with"
	SKValue  item.Value // operand (or BETWEEN low bound)
	SKValue2 item.Value // BETWEEN high bound
}

KeyCondition is the restricted condition shape Query accepts:

pk = :v
pk = :v AND sk <op> :v
pk = :v AND sk BETWEEN :lo AND :hi
pk = :v AND begins_with(sk, :prefix)

func ParseKeyCondition

func ParseKeyCondition(src string, env *Env) (*KeyCondition, *awshttp.APIError)

ParseKeyCondition parses and validates a KeyConditionExpression.

type Path

type Path struct {
	// contains filtered or unexported fields
}

Path is a parsed document path (a.b[0].c).

func (Path) Get

func (p Path) Get(it item.Item) (item.Value, bool)

Get resolves the path against an item; ok=false when any step is missing.

func (Path) Remove

func (p Path) Remove(it item.Item) *awshttp.APIError

Remove deletes the value at the path (missing paths are a no-op).

func (Path) Root

func (p Path) Root() string

Root returns the top-level attribute name.

func (Path) Set

func (p Path) Set(it item.Item, v item.Value) *awshttp.APIError

Set writes a value at the path, creating intermediate maps for missing map segments (DynamoDB requires parents to exist EXCEPT the final segment; we match that: missing intermediate levels error).

func (Path) String

func (p Path) String() string

String renders the path for error messages.

type Projection

type Projection struct {
	// contains filtered or unexported fields
}

Projection is a parsed projection expression: the paths to keep.

func ParseProjection

func ParseProjection(src string, env *Env) (*Projection, *awshttp.APIError)

ParseProjection parses a ProjectionExpression.

func (*Projection) Apply

func (pr *Projection) Apply(it item.Item) item.Item

Apply projects an item down to the requested paths.

type Update

type Update struct {
	// contains filtered or unexported fields
}

Update is a parsed update expression: SET / REMOVE / ADD / DELETE clauses.

func ParseUpdate

func ParseUpdate(src string, env *Env) (*Update, *awshttp.APIError)

ParseUpdate parses an update expression.

func (*Update) Apply

func (u *Update) Apply(orig item.Item) (item.Item, *awshttp.APIError)

Apply runs the update against a copy of the item and returns the new item. The caller re-validates key immutability and size afterward.

Jump to

Keyboard shortcuts

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