Expr class

Helper class for building expressions in a type-safe, fluent manner.

This class provides a builder pattern that prevents injection attacks by only allowing structured expression construction.

All atomic field operations (increment, multiply, etc.) can be expressed using this unified expression system.

Example usage:

// Simple expression: price * quantity
Expr.field('price') * Expr.field('quantity')

// Increment: balance + 100
Expr.field('balance') + Expr.value(100)

// Multiply: price * 0.9 (10% discount)
Expr.field('price') * Expr.value(0.9)

// Complex expression with parentheses: (price * quantity) + tax - discount
(Expr.field('price') * Expr.field('quantity')) + Expr.field('tax') - Expr.field('discount')

// Multi-level parentheses: ((a + b) * c) / (d - e)
((Expr.field('a') + Expr.field('b')) * Expr.field('c')) / (Expr.field('d') - Expr.field('e'))

// Nested expressions with functions: min((price * quantity), maxPrice)
Expr.min(
  (Expr.field('price') * Expr.field('quantity')),
  Expr.field('maxPrice')
)

// Complex calculation: ((base * rate) + tax) * (1 - discount)
((Expr.field('base') * Expr.field('rate')) + Expr.field('tax')) * (Expr.value(1) - Expr.field('discount'))

// With functions: min(price, maxPrice)
Expr.min(Expr.field('price'), Expr.field('maxPrice'))

// Server timestamp
Expr.now()

Parentheses Support: The expression system fully supports parentheses for controlling evaluation order. Dart's operator precedence rules apply, and parentheses can be nested to any depth. The expression AST correctly represents the parenthesized structure.

Constructors

Expr()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

abs(ExprNode x) FunctionCall
Creates an absolute value function call: abs(x)
ceil(ExprNode x) FunctionCall
Creates a ceil function call: ceil(x)
field(String fieldName) FieldRef
Creates a field reference expression.
floor(ExprNode x) FunctionCall
Creates a floor function call: floor(x)
ifElse(ExprNode condition, dynamic thenValue, dynamic elseValue) IfElse
Conditional: if condition then thenValue else elseValue. Use with isUpdate/isInsert for update-vs-insert semantics.
isInsert() IsInsert
Predicate: true when the current operation is an insert (e.g. upsert inserted new row).
isUpdate() IsUpdate
Predicate: true when the current operation is an update (e.g. upsert matched existing row).
max(ExprNode a, ExprNode b) FunctionCall
Creates a max function call: max(a, b)
min(ExprNode a, ExprNode b) FunctionCall
Creates a min function call: min(a, b)
now() TimestampExpr
Creates a server timestamp expression.
round(ExprNode x) FunctionCall
Creates a round function call: round(x)
value(num value) Constant
Creates a constant value expression.
when(ExprNode condition, dynamic value, {dynamic otherwise}) When
Single-branch conditional: when condition holds use value, otherwise use otherwise (default null).