Expressions
Auto-generated documentation for dynamo_query.expressions module.
Expression builders.
- dynamo-query / Modules / Dynamo Query / Expressions
ConditionExpression
class ConditionExpression(BaseConditionExpression):
def __init__(
key: str,
operator: ConditionExpressionOperatorStr = '=',
value: Any = None,
):
Part of ConditionExpression.
ConditionExpression(key='name', operator=Operator.IN, value='test').render()
# '{key} IN ({test__value})'
Arguments
key
- Key name.operator
-ConditionExpressionOperator
value
- Value name to match.
See also
ConditionExpression().get_format_keys
def get_format_keys() -> Set[str]:
Get required format keys.
Returns
A set of keys.
ConditionExpression().get_format_values
def get_format_values() -> Set[str]:
Get required format values without value postfix.
Returns
A set of keys.
ConditionExpression().get_operators
def get_operators() -> Set[ConditionExpressionOperatorStr]:
Get a set of all operators that used in expession group.
ExpressionError
class ExpressionError(Exception):
ProjectionExpression
class ProjectionExpression(BaseExpression):
def __init__(*keys: str):
Renderer for a format-ready ProjectionExpression.
from dynamo_query.expressions import ProjectionExpression
projection_expression = ProjectionExpression(
['first_name', 'last_name']
)
projection_expression.render() # '{first_name}, {last_name}'
Arguments
keys
- Keys to add to expressions.
See also
ProjectionExpression().get_format_keys
def get_format_keys() -> Set[str]:
Get required format keys.
Returns
A set of keys.
ProjectionExpression().get_format_values
def get_format_values() -> Set[str]:
Get required format values without value postfix.
Returns
A set of keys.
ProjectionExpression().get_operators
def get_operators() -> Set[ConditionExpressionOperatorStr]:
Get a set of all operators that used in expession group.
UpdateExpression
class UpdateExpression(BaseExpression):
def __init__(
update: Iterable[str] = tuple(),
set_if_not_exists: Iterable[str] = tuple(),
add: Iterable[str] = tuple(),
delete: Iterable[str] = tuple(),
remove: Iterable[str] = tuple(),
*args: str,
):
Renderer for format-ready UpdateExpression.
update_expression = UpdateExpression(
update=['first_name'],
set_if_not_exists=['created_at'],
add=['tags'],
)
update_expression
# (
# 'SET {first_name} = {first_name__value},'
# ' {created_at} = if_not_exists({created_at}, {created_at__value})
# ' ADD {tags} {tags__value}'
# )
Arguments
args
- Keys to use SET expression, use to update values.update
- Keys to use SET expression, use to update values.set_if_not_exists
- Keys to use SET expression, use to add new keys.add
- Keys to use ADD expression, use to extend lists.delete
- Keys to use DELETE expression, use to subtract lists.remove
- Keys to use REMOVE expression, use to remove values.
See also
UpdateExpression().get_format_keys
def get_format_keys() -> Set[str]:
Get required format keys.
Returns
A set of keys.
UpdateExpression().get_format_values
def get_format_values() -> Set[str]:
Get required format values without value postfix.
Returns
A set of keys.
UpdateExpression().get_operators
def get_operators() -> Set[ConditionExpressionOperatorStr]:
Get a set of all operators that used in expession group.
UpdateExpression().validate_input_data
def validate_input_data(data: Dict[(str, Any)]) -> None:
Validate data that is used to format the expression.
ADD
and DELETE
directives allow only sets and numbers.
Arguments
data
- Data to validate.
Raises
ExpressionError
- If data is invalid.