Reconstructors

BaseReconstructor

class cerami.reconstructor.BaseReconstructor

The base class for all Reconstructors

Reconstructors are used to interpret data from a DynamoDB response. All classes that inherit from BaseReconstructor implement reconstruct() which takes in the DynamoDB data and manipulates it accordingly.

For example, the ModelReconstructor converts the raw DynamoDB response data back into the Model of the corresponding table

reconstruct(item_dict)

The abstract reconstruct method to be implemented by child classes

Its purpose it to convert the item_dict from DynamoDB

Parameters

item_dict – a dict from DynamoDB. It will be in the format like {"a_column": {"S": "my_value"}}

Raises

Exception – Not Implemented

ModelReconstructor

class cerami.reconstructor.ModelReconstructor(model_cls)

A Reconstructor class to convert the DynamoDB response data back into a Model

__init__(model_cls)

constructor for ModelReconstructor

Parameters

model_cls – the class of the Model to convert the data into

reconstruct(item_dict)

Convert the item_dict into a Model instance

Iterates over all columns in the model_cls and tries to set the value based on the item_dict’s keys

Parameters

item_dict – a dict from DynamoDB. It will be in the format like {"a_column": {"S": "my_value"}}

Returns

an instance of model_cls

RawReconstructor

class cerami.reconstructor.RawReconstructor

A Reconstructor class to return the data back exactly as it was given

reconstruct(item_dict)

Return the item_dict

Parameters

item_dict – a dict from DynamoDB. It will be in the format like {"a_column": {"S": "my_value"}}

Returns

the item_dict passed in