flywheel.query module¶
Query and Scan builders
-
exception
flywheel.query.
DuplicateEntityException
[source]¶ Bases:
exceptions.ValueError
Raised when too many results are found.
-
exception
flywheel.query.
EntityNotFoundException
[source]¶ Bases:
exceptions.ValueError
Raised when results are expected and not found.
-
class
flywheel.query.
Query
(engine, model)[source]¶ Bases:
object
An object used to query dynamo tables
See the
Engine
for query examplesParameters: engine :
Engine
model : class
Subclass of
Model
-
all
(desc=False, consistent=False, attributes=None, filter_or=False)[source]¶ Return the query results as a list
Parameters: desc : bool, optional
Return results in descending order (default False)
consistent : bool, optional
Force a consistent read of the data (default False)
attributes : list, optional
List of fields to retrieve from dynamo. If supplied, returns dicts instead of model objects.
filter_or : bool, optional
If True, multiple filter() constraints will be joined with an OR (default AND).
Returns: results : list
-
count
(filter_or=False)[source]¶ Find the number of elements the match this query
Parameters: filter_or : bool, optional
If True, multiple filter() constraints will be joined with an OR (default AND).
Returns: count : int
-
delete
(filter_or=False)[source]¶ Delete all items that match the query
Parameters: filter_or : bool, optional
If True, multiple filter() constraints will be joined with an OR (default AND).
-
filter
(*conditions, **kwargs)[source]¶ Add a Condition to constrain the query
Notes
The conditions may be passed in as positional arguments:
engine.query(User).filter(User.id == 12345)
Or they may be passed in as keyword arguments:
engine.query(User).filter(firstname='Monty', lastname='Python')
The limitations of the keyword method is that you may only create equality conditions. You may use both types in a single filter:
engine.query(User).filter(User.num_friends > 10, name='Monty')
-
first
(desc=False, consistent=False, attributes=None, filter_or=False)[source]¶ Return the first result of the query, or None if no results
Parameters: desc : bool, optional
Return results in descending order (default False)
consistent : bool, optional
Force a consistent read of the data (default False)
attributes : list, optional
List of fields to retrieve from dynamo. If supplied, returns dicts instead of model objects.
filter_or : bool, optional
If True, multiple filter() constraints will be joined with an OR (default AND).
Returns: result :
Model
or None
-
gen
(desc=False, consistent=False, attributes=None, filter_or=False)[source]¶ Return the query results as a generator
Parameters: desc : bool, optional
Return results in descending order (default False)
consistent : bool, optional
Force a consistent read of the data (default False)
attributes : list, optional
List of fields to retrieve from dynamo. If supplied, gen() will iterate over dicts instead of model objects.
filter_or : bool, optional
If True, multiple filter() constraints will be joined with an OR (default AND).
Returns: results : generator
-
one
(consistent=False, attributes=None, filter_or=False)[source]¶ Return the result of the query. If there is not exactly one result, raise a ValueError
Parameters: consistent : bool, optional
Force a consistent read of the data (default False)
attributes : list, optional
List of fields to retrieve from dynamo. If supplied, returns dicts instead of model objects.
filter_or : bool, optional
If True, multiple filter() constraints will be joined with an OR (default AND).
Returns: result :
Model
Raises: If no entity is found. Subclasses
ValueError
.If more than one entity is found. Subclasses
ValueError
.
-
-
class
flywheel.query.
Scan
(engine, model)[source]¶ Bases:
flywheel.query.Query
An object used to scan dynamo tables
scans are like Queries except they don’t use indexes. This means they iterate over all data in the table and are SLOW
Parameters: engine :
Engine
model : class
Subclass of
Model