dql.expressions module

Objects to model nested update/constraint expressions

class dql.expressions.BetweenConstraint(field, low, high)[source]

Bases: dql.expressions.ConstraintExpression

Constraint expression for BETWEEN low AND high

build(visitor)[source]
classmethod from_clause(clause)[source]

Factory method

range_field[source]
class dql.expressions.Conjunction(pieces)[source]

Bases: dql.expressions.ConstraintExpression

Use AND and OR to join 2 or more expressions

classmethod and_(constraints)[source]

Factory for a group AND

build(visitor)[source]
classmethod from_clause(clause)[source]

Factory method

classmethod or_(constraints)[source]

Factory for a group OR

possible_hash_fields()[source]
possible_range_fields()[source]
remove_index(index)[source]

This one takes some explanation. When we do a query with a WHERE statement, it may end up being a scan and it may end up being a query. If it is a query, we need to remove the hash and range key constraints from the expression and return that as the query_constraints. The remaining constraints, if any, are returned as the filter_constraints.

class dql.expressions.ConstraintExpression[source]

Bases: dql.expressions.Expression

Base class and entry point for constraint expressions

e.g. WHERE foo = 1

build(visitor)[source]
classmethod from_clause(clause)[source]

Factory method

classmethod from_where(where)[source]

Factory method for creating the top-level expression

hash_field[source]

The field of the hash key this expression can select, if any

possible_hash_fields()[source]

Set of field names this expression could possibly be selecting for the hash key of a query.

Hash keys must be exactly specified with “hash_key = value”

possible_range_fields()[source]

Set of field names this expression could possibly be selecting for the range key of a query.

Range keys can use operations such as <, >, <=, >=, begins_with, etc.

range_field[source]

The field of the range key this expression can select, if any

class dql.expressions.DummyVisitor(reserved_words=None)[source]

Bases: dql.expressions.Visitor

No-op visitor for testing

get_field(field)[source]

No-op

get_value(value)[source]

No-op

class dql.expressions.Expression[source]

Bases: object

Base class for all expressions and expression fragments

build(visitor)[source]

Build string expression, using the visitor to encode values

class dql.expressions.Field(field)[source]

Bases: dql.expressions.Expression

Wrapper for a field in an expression

build(visitor)[source]
class dql.expressions.FieldValue(field, value)[source]

Bases: dql.expressions.Expression

A field-value pair used in an expression

build(visitor)[source]
classmethod from_clause(clause)[source]

Factory method

class dql.expressions.FunctionConstraint(fn_name, field, operand=None)[source]

Bases: dql.expressions.ConstraintExpression

Constraint for function expressions e.g. attribute_exists(field)

build(visitor)[source]
classmethod from_clause(clause)[source]

Factory method

range_field[source]
class dql.expressions.InConstraint(field, values)[source]

Bases: dql.expressions.ConstraintExpression

Constraint expression for membership in a set

build(visitor)[source]
classmethod from_clause(clause)[source]

Factory method

class dql.expressions.Invert(constraint)[source]

Bases: dql.expressions.ConstraintExpression

Invert another constraint expression with NOT

build(visitor)[source]
class dql.expressions.OperatorConstraint(field, operator, value)[source]

Bases: dql.expressions.ConstraintExpression

Constraint expression for operations, e.g. foo = 4

build(visitor)[source]
classmethod from_clause(clause)[source]

Factory method

hash_field[source]
range_field[source]
remove_index(index)[source]

See remove_index().

This is called if the entire WHERE expression is just a “hash_key = value”. In this case, the query_constraints are just this constraint, and there are no filter_constraints.

class dql.expressions.SetFunction(fn_name, value1, value2)[source]

Bases: dql.expressions.Expression

Expression fragment for a function used in a SET statement

e.g. if_not_exists(field, value)

build(visitor)[source]
classmethod from_clause(clause)[source]

Factory method

class dql.expressions.SizeConstraint(field, operator, value)[source]

Bases: dql.expressions.ConstraintExpression

Constraint expression for size() function

build(visitor)[source]
classmethod from_clause(clause)[source]

Factory method

class dql.expressions.TypeConstraint(fn_name, field, operand=None)[source]

Bases: dql.expressions.FunctionConstraint

Constraint for attribute_type() function

classmethod from_clause(clause)[source]

Factory method

class dql.expressions.UpdateAdd(updates)[source]

Bases: dql.expressions.Expression

Expression fragment for an ADD statement

build(visitor)[source]
classmethod from_clause(clause)[source]

Factory method

class dql.expressions.UpdateDelete(updates)[source]

Bases: dql.expressions.Expression

Expression fragment for a DELETE statement

build(visitor)[source]
classmethod from_clause(clause)[source]

Factory method

class dql.expressions.UpdateExpression(expressions)[source]

Bases: dql.expressions.Expression

Entry point for Update expressions

build(visitor)[source]
classmethod from_update(update)[source]

Factory for creating an Update expression

class dql.expressions.UpdateRemove(fields)[source]

Bases: dql.expressions.Expression

Expression fragment for a REMOVE statement

build(visitor)[source]
classmethod from_clause(clause)[source]

Factory method

class dql.expressions.UpdateSetMany(updates)[source]

Bases: dql.expressions.Expression

Expression fragment for multiple set statements

build(visitor)[source]
classmethod from_clause(clause)[source]

Factory method

class dql.expressions.UpdateSetOne(field, value1, op=None, value2=None)[source]

Bases: dql.expressions.Expression

Expression fragment for a single SET statement

build(visitor)[source]
classmethod from_clause(clause)[source]

Factory method

class dql.expressions.Value(val)[source]

Bases: dql.expressions.Expression

Wrapper for a value in an expression

build(visitor)[source]
class dql.expressions.Visitor(reserved_words=None)[source]

Bases: object

Visitor that replaces field names and values with encoded versions

Parameters:

reserved_words : set, optional

Set of (uppercase) words that are reserved by DynamoDB. These are used when encoding field names. If None, will default to encoding all fields.

attribute_names[source]

Dict of encoded field names to original names

expression_values[source]

Dict of encoded variable names to the variables

get_field(field)[source]

Get the safe representation of a field name

For example, since ‘order’ is reserved, it would encode it as ‘#f1’

get_value(value)[source]

Replace variable names with placeholders (e.g. ‘:v1’)

dql.expressions.field_or_value(clause)[source]

For a clause that could be a field or value, create the right one and return it