UniformList¶
-
class
cerami.datatype.
UniformList
(datatype, default=None, column_name='')¶ A class to represent Lists of entirely the same datatype
The Base List class uses a Guesser to try and determine the datatype to use for the each item in the array. A UniformList does not need to guess, since the datatype is consistent and stored as an attribute
-
__init__
(datatype, default=None, column_name='')¶ constructor for UniformList
- Parameters
datatype – Any DynamoDataType that each item in the List will be
default – a default value for the column. It can be a value or function
column_name – a string defining the name of the column on the table
-
append
(array)¶ Build an expression to add the array to the end of the existing column data
It can only be used in SET UpdateExpressions.
- Parameters
array – can be a list or single value to be appended. When it is a single value, it is automatically put inside its own array, before building the expression.
- Returns
A ListAppendExpression
For example:
Person.update \ .key(Person.email == "test@test.com") .set(Person.toys.append({"color": "red", "name": "car"})
-
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"))
-
index
(idx)¶ build a duplicate datatype with the _index set to idx
When forming a Request that involves a specific item in the UniformList, that item can be specified using this index() method
- Parameters
idx – a number for the index of the desired item in the list
- Returns
A copy of the datatype with _index set
For example:
MyModel.scan.filter(MyModel.number_list.index(2) == 100).execute()
-
set_column_name
(val)¶ Update the column_name of this instance
- Parameters
value – a string for the new column name
-