Model

The Model class is used to represent a DynamoDB table. It consists of class-level DynamoDataTypes that represent all columns in the table. The class can be extended to include any helper methods to define business logic related to the table, and includes helper methods to perform DynamoDB requests.

Model

class cerami.model.Model(**data_kwargs)

This is the base class for all models.

It automatically uses the ModelMeta to define properties for interacting with DynamoDB tables. It should be used to create all classes that need make requests to DynamoDB.

Models consist of a series of DynamoDataTypes that define which columns are to be saved in the database. Each datatype is also an instance variable that can be manipulated through any methods defined on helper methods.

For example:

from cerami.decorators import primary_key
from cerami.datatype import String

@primary_key("email")
class Person(Model):
   __tablename__ = "people"

   email = String()
   name = Sting()

person = Person(email="test@test.com", name="Mom")
__init__(**data_kwargs)

set all column values from data

It will set any value not present in data but part of the models columns to None

Parameters

**data_kwargs – Each kwarg should be the name of one of the columns with a corresponding value

as_item()

return all data values in a format for dynamodb

Returns

a dictionary of the model in a format recognized by DynamoDB

For example:

person = Person(email="test@test.com", name="Mom")
person.as_item()
{'email': {'S': 'test@test.com'}, 'name': {'S': 'Mom'}}
delete()

delete this record from the database

Automatically perform a DeleteRequest based on the model’s primary key

Returns

a DeleteResponse

put()

add this record to the database

Automatically perform a PutRequest with the objects data

Returns

a SaveResponse

update()

update this record in the database

Automatically perform an UpdateRequest based on the models attributes. It will only update columns that have been initialized or changed.

Returns

a SaveResponse

ModelMeta

class cerami.model.ModelMeta

The meta class for all Models

This meta class is automatically sets the column names on every column attribute and defines some class level properties for generating requests

_columns

An array for accessing all datatypes defined on the Model

property delete

Create a DeleteRequest for the Model

Returns

a DeleteRequest object

property get

Create a GetRequest for the Model

Returns

a GetRequest object

property put

Create a PutRequest for the Model

Returns

a PutRequest object

property query

Create a QueryRequest for the Model

Returns

a QueryRequest object

property scan

Create a ScanRequest for the Model

Returns

a ScanRequest object

property update

Create an UpdateRequest for the Model

Returns

an UpdateRequest object