ModelMap¶
-
class
cerami.datatype.
ModelMap
(model_cls, translator_cls=<class 'cerami.datatype.translator.model_translator.ModelTranslator'>, column_name='')¶ A class to represent a nested model as a Map
A ModelMap automatically sets the column_names to use the dot notation when accessing the nested attributes. This allows direct reference to nested keys when making requests. For example:
Parent.scan.filter(Parent.child.name == 'Zac')
-
__init__
(model_cls, translator_cls=<class 'cerami.datatype.translator.model_translator.ModelTranslator'>, column_name='')¶ constructor for ModelMap
- Parameters
model_cls – the class of the nested Model being used
translator_cls – A Translator class to manipulate data to/from dynamodb. Defaults to the ModelTranslator
column_name – a string defining the name of the column on the table
-
between
(greater_than, less_than)¶ Build a BetweenExpression
BetweenExpression can be used with the filter() on the model or as a KeyConditionExpression on the sort key of a query
- Parameters
greater_than – a value that the query is greater than or equal to
less_than – a value that the query is less than or equal to
- Returns
A BetweenExpression
For example:
Person.scan.filter(Person.age.between(10, 20))
-
build
(val)¶ build the column value based on the val passed in
building is called automatically by the DynamoDataAttribute when the model is initialized. It will use the default value when present if the val passed in is None
- Parameters
val – A value that will be used to build the attribute on the instance
- Returns
The passed in val or the default when the default is set
-
in_
(*values)¶ Build an InExpression
InExpressions can only be used with filter() on the model, it cannot be part of a KeyConditionExpression. The will filter for the table for values that match exactly any of the values passed in as arguments
- Parameters
values – anything value to use to filter the table
- Returns
An InExpression
For example:
Person.scan.filter(Person.name.in_("Mom", "Dad"))
-
set_column_name
(val)¶ Update the column_name of this instance.
Automatically apply a dot notation chain from the this column_name to all of the nested models datatypes column_names
- Parameters
val – the name of the column
For example:
class Child(object): name = String() class Parent(db.Model): child = ModelMap(Child) Parent.child.name.column_name # <== 'child.name'
-