type_bridge.expressions.arithmetic¶
arithmetic
¶
Arithmetic expressions for TypeQL queries.
TypeQL supports six infix operators with standard precedence: +, -, *, /, %, ^
These can be used in let assignments and reduce clauses to perform arithmetic on query variables and literals.
ArithmeticExpr
dataclass
¶
Bases: Expression
Binary arithmetic expression for TypeQL queries.
Represents an infix operation like $x + $y or $price * 1.1.
Example
expr = ArithmeticExpr("$x", "+", "$y") expr.to_typeql("$unused") '($x + $y)'
In a let assignment:¶
let $total = ($price * $quantity);¶
to_ast
¶
to_value_ast
¶
Convert to an ArithmeticValue AST node.
Source code in type_bridge/expressions/arithmetic.py
to_typeql
¶
Generate parenthesized TypeQL arithmetic expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var
|
str
|
Ignored (arithmetic expressions use their own operands) |
required |
Returns:
| Type | Description |
|---|---|
str
|
Parenthesized TypeQL expression, e.g. "($x + $y)" |
Source code in type_bridge/expressions/arithmetic.py
get_attribute_types
¶
add
¶
Create an addition expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
str | int | float
|
Variable name or numeric literal |
required |
right
|
str | int | float
|
Variable name or numeric literal |
required |
Returns:
| Type | Description |
|---|---|
ArithmeticExpr
|
ArithmeticExpr representing |
Example
add("x", "y").to_typeql("") '($x + $y)' add("price", 10).to_typeql("") '($price + 10)'
Source code in type_bridge/expressions/arithmetic.py
sub
¶
Create a subtraction expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
str | int | float
|
Variable name or numeric literal |
required |
right
|
str | int | float
|
Variable name or numeric literal |
required |
Returns:
| Type | Description |
|---|---|
ArithmeticExpr
|
ArithmeticExpr representing |
Source code in type_bridge/expressions/arithmetic.py
mul
¶
Create a multiplication expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
str | int | float
|
Variable name or numeric literal |
required |
right
|
str | int | float
|
Variable name or numeric literal |
required |
Returns:
| Type | Description |
|---|---|
ArithmeticExpr
|
ArithmeticExpr representing |
Source code in type_bridge/expressions/arithmetic.py
div
¶
Create a division expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
str | int | float
|
Variable name or numeric literal |
required |
right
|
str | int | float
|
Variable name or numeric literal |
required |
Returns:
| Type | Description |
|---|---|
ArithmeticExpr
|
ArithmeticExpr representing |
Source code in type_bridge/expressions/arithmetic.py
mod
¶
Create a modulo expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
str | int | float
|
Variable name or numeric literal |
required |
right
|
str | int | float
|
Variable name or numeric literal |
required |
Returns:
| Type | Description |
|---|---|
ArithmeticExpr
|
ArithmeticExpr representing |
Source code in type_bridge/expressions/arithmetic.py
pow_
¶
Create an exponentiation expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
str | int | float
|
Variable name or numeric literal |
required |
right
|
str | int | float
|
Variable name or numeric literal |
required |
Returns:
| Type | Description |
|---|---|
ArithmeticExpr
|
ArithmeticExpr representing |