Documentation
¶
Index ¶
- Constants
- Variables
- func CheckReservedWords(node Node) error
- func IsReservedWord(name string) bool
- type BetweenExpr
- type ComparisonExpr
- type Evaluator
- type FunctionExpr
- type InExpr
- type Lexer
- type LogicalExpr
- type Node
- type NotExpr
- type Parser
- type PathElement
- type PathElementType
- type PathExpr
- type ProjectionExpr
- type ReservedWordError
- type Token
- type TokenType
- type UpdateAction
- type UpdateExpr
- type UpdateItem
- type ValuePlaceholder
Constants ¶
const ( PrecOR int PrecAND PrecNOT PrecComparison PrecArithmetic )
Variables ¶
var ( ErrValuePlaceholderNotFound = errors.New("value placeholder not found") ErrUnsupportedNodeType = errors.New("unsupported node type") ErrSizeExpectsOneArg = errors.New("size() expects 1 argument") ErrAttributeExistsExpectsPath = errors.New("attribute_exists() expects a path") ErrAttributeExistsExpectsOne = errors.New("attribute_exists() expects 1 argument") ErrAttributeNExistsExpectsPath = errors.New("attribute_not_exists() expects a path") ErrAttributeNExistsExpectsOne = errors.New("attribute_not_exists() expects 1 argument") ErrBeginsWithExpectsTwo = errors.New("begins_with() expects 2 arguments") ErrContainsExpectsTwo = errors.New("contains() expects 2 arguments") ErrAttributeTypeExpectsTwo = errors.New("attribute_type() expects 2 arguments") ErrListAppendExpectsTwo = errors.New("list_append() expects 2 arguments") ErrUnknownFunction = errors.New("unknown function") ErrUpdatePathMustBePathExpr = errors.New("update item path must be a PathExpr") ErrExpectedMapForKey = errors.New("expected map for key") ErrExpectedListAtIndex = errors.New("expected list at index") ErrExpectedListForIndex = errors.New("expected list for index") ErrIndexOutOfRange = errors.New("index out of range") ErrExpectedMapForM = errors.New("expected map for M") ErrExpectedListForL = errors.New("expected list for L") ErrUnsupportedArithmeticOp = errors.New("unsupported arithmetic operator") ErrIfNotExistsExpectsTwo = errors.New("if_not_exists() expects 2 arguments") ErrDeleteValueMustBeSet = errors.New("DELETE value must be a set") ErrSSValueMustBeSlice = errors.New("SS value must be []string") ErrCurrentValueMustBeMap = errors.New("current value must be a map") ErrCurrentSSValueMustBeSlice = errors.New("current SS value must be []string") ErrNSValueMustBeSlice = errors.New("NS value must be []string") ErrCurrentNSValueMustBeSlice = errors.New("current NS value must be []string") ErrBSValueMustBeSlice = errors.New("BS value must be [][]byte") ErrCurrentBSValueMustBeSlice = errors.New("current BS value must be [][]byte") ErrSetTypeMismatch = errors.New( "ADD: existing set type does not match the type being added", ) ErrSetSizeOverflow = errors.New("set size overflow") ErrInvalidSizeArg = errors.New( "size() only supports String, Binary, Map, List, and Set types", ) ErrUnsupportedAddType = errors.New( "ADD action is only supported for Number and Set types", ) // ErrDocumentPathInvalidForUpdate matches the real AWS ValidationException // message: SET cannot create a nested attribute under a parent map that // does not already exist on the item. // https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html ErrDocumentPathInvalidForUpdate = errors.New( "the document path provided in the update expression is invalid for update", ) // ErrOperandIncorrectType is returned when an update expression operand's // runtime type does not match what the operation requires (e.g. ADD/DELETE // against an existing attribute that is not a Number/Set, or +/- against a // non-Number operand). ErrOperandIncorrectType = errors.New( "an operand in the update expression has an incorrect data type", ) // ErrOverlappingDocumentPaths is returned when two actions in the same // UpdateExpression reference the same or overlapping document paths. ErrOverlappingDocumentPaths = errors.New( "two document paths overlap with each other; must remove or rewrite one of these paths", ) // ErrContainsOperandsNotDistinct matches the documented contains() restriction: // "The path and the operand must be distinct. That is, contains (a, a) returns an error." // https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html ErrContainsOperandsNotDistinct = errors.New( "contains() arguments must be distinct", ) )
Sentinel errors for evaluator.
var ( ErrExpectedRParen = errors.New("expected ) after function args") ErrExpectedLParen = errors.New("expected ( after function name") ErrExpectedIdentifierDot = errors.New("expected identifier after dot") ErrExpectedRBracket = errors.New("expected ]") ErrExpectedANDInBetween = errors.New("expected AND in BETWEEN") ErrExpectedLParenAfterIN = errors.New("expected ( after IN") ErrExpectedRParenAfterIN = errors.New("expected ) after IN candidates") ErrExpectedEqualInSET = errors.New("expected = in SET") ErrUnexpectedToken = errors.New("unexpected token") ErrUnexpectedOperand = errors.New("unexpected operand token") ErrExpectedIndex = errors.New("expected index") ErrExpectedRParen2 = errors.New("expected )") // ErrTooManyINValues matches the documented IN limit: "The list can // contain up to 100 values, separated by commas." // https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html ErrTooManyINValues = errors.New("IN operator can have up to 100 values") // ErrDuplicateUpdateSection matches AWS rejecting an UpdateExpression that // repeats the same SET/REMOVE/ADD/DELETE keyword: "each action keyword can // appear only once." // https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html ErrDuplicateUpdateSection = errors.New( "can only be used once in an update expression", ) )
Sentinel errors for parser.
var ErrReservedWord = errors.New("reserved keyword")
ErrReservedWord identifies a *ReservedWordError via errors.Is/errors.As. Its own text is lowercase Go style; the AWS-facing wording lives on ReservedWordError.Error() instead -- see that doc comment.
Functions ¶
func CheckReservedWords ¶
CheckReservedWords walks a parsed expression AST and returns a *ReservedWordError for the first bare (non-#placeholder) document-path segment that collides with a reserved word. Every path segment is checked independently, so a nested path like a.SIZE is rejected exactly like a top-level SIZE would be -- DynamoDB requires an expression attribute name alias at whichever path level the reserved word appears (see Expressions.ExpressionAttributeNames.html's "Nested attributes" guidance to alias each element in the document path).
func IsReservedWord ¶
IsReservedWord reports whether name is a DynamoDB reserved word. Matching is case-insensitive, per ReservedWords.html ("This list isn't case-sensitive.").
Types ¶
type BetweenExpr ¶
type ComparisonExpr ¶
ComparisonExpr represents a comparison expression (=, <>, <, >, <=, >=).
type Evaluator ¶
type Evaluator struct {
Item map[string]any
AttrNames map[string]string
AttrValues map[string]any
// UpdatedPaths tracks the top-level attribute names touched by ApplyUpdate.
UpdatedPaths map[string]struct{}
// contains filtered or unexported fields
}
func (*Evaluator) ApplyProjection ¶
func (e *Evaluator) ApplyProjection(p *ProjectionExpr) map[string]any
func (*Evaluator) ApplyUpdate ¶
func (e *Evaluator) ApplyUpdate(u *UpdateExpr) error
type FunctionExpr ¶
FunctionExpr represents a function call expression (e.g., size, attribute_exists).
type LogicalExpr ¶
LogicalExpr represents a logical expression (AND, OR) combining two nodes.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func (*Parser) ParseCondition ¶
ParseCondition parses a ConditionExpression.
func (*Parser) ParseProjection ¶
func (p *Parser) ParseProjection() (*ProjectionExpr, error)
ParseProjection parses a ProjectionExpression.
func (*Parser) ParseUpdate ¶
func (p *Parser) ParseUpdate() (*UpdateExpr, error)
ParseUpdate parses an UpdateExpression.
type PathElement ¶
type PathElement struct {
Name string
Index int
Type PathElementType
}
type PathElementType ¶
type PathElementType int
const ( ElementKey PathElementType = iota ElementIndex )
type PathExpr ¶
type PathExpr struct {
Elements []PathElement
}
PathExpr represents a path expression (e.g., a.b[0]).
type ProjectionExpr ¶
type ProjectionExpr struct {
Paths []Node // PathExpr
}
ProjectionExpr represents a projection expression listing the paths to include.
type ReservedWordError ¶
type ReservedWordError struct {
Word string
}
ReservedWordError carries the offending bare attribute name, preserving its original case as written in the expression. Its Error() text matches DynamoDB's observed runtime wording, e.g. "Invalid KeyConditionExpression: Attribute name is a reserved keyword; reserved keyword: hash" -- confirmed via https://github.com/aws/aws-sdk-php/issues/1233. The developer guide (ReservedWords.html, Expressions.ExpressionAttributeNames.html) documents the underlying rule but not this verbatim ValidationException string.
func (*ReservedWordError) Error ¶
func (e *ReservedWordError) Error() string
func (*ReservedWordError) Unwrap ¶
func (e *ReservedWordError) Unwrap() error
type TokenType ¶
type TokenType int
const ( TokenEOF TokenType = iota TokenError // TokenIdentifier represents identifiers and placeholders. TokenIdentifier // #name or pk or info.tags TokenValue // :val // TokenEqual represents operators. TokenEqual // = TokenNotEqual // <> TokenLess // < TokenGreater // > TokenLessEqual // <= TokenGreaterEqual // >= TokenPlus // + TokenMinus // - TokenLParen // ( TokenRParen // ) TokenComma // , TokenDot // . TokenLBracket // [ TokenRBracket // ] // TokenAND represents keywords. TokenAND TokenOR TokenNOT TokenBETWEEN TokenIN TokenSET TokenREMOVE TokenADD TokenDELETE // TokenSize represents function keywords. TokenSize TokenAttributeExists TokenAttributeNotExists TokenBeginsWith TokenContains TokenAttributeType TokenIfNotExists TokenListAppend )
type UpdateAction ¶
type UpdateAction struct {
Items []UpdateItem
Type TokenType
}
type UpdateExpr ¶
type UpdateExpr struct {
Actions []UpdateAction
}
UpdateExpr represents an update expression with one or more actions (SET, REMOVE, ADD, DELETE).
type UpdateItem ¶
type ValuePlaceholder ¶
type ValuePlaceholder struct {
Name string
}
ValuePlaceholder represents a value placeholder (e.g., :val).