flywheel.models module

Model code

class flywheel.models.Model(*args, **kwargs)[source]

Bases: object

Base class for all tube models

For documentation on the metadata fields, check the attributes on the ModelMetadata class.

Attributes

__metadata_class__ alias of ModelMetadata
__metadata__ (dict) For details see Metadata
meta_ (ModelMetadata) The metadata for the model
__engine__ (Engine) Cached copy of the Engine that was used to save/load the model. This will be set after saving or loading a model.
__dirty__ (set) The set of all immutable fields that have been changed since the last save operation.
__cache__ (dict) The last seen value that was stored in the database. This is used to construct the expects dict when making updates that raise on conflict.
__incrs__ (dict) Mapping of fields to atomic add/delete operations for numbers and sets.
add_(**kwargs)[source]

Atomically add to a set

cached_(name, default=None)[source]

Get the cached (server) value of a field

construct_ddb_expects_(fields=None)[source]

Construct a dynamo “expects” mapping based on the cached fields

ddb_dump_()[source]

Return a dict for inserting into DynamoDB

ddb_dump_cached_(name)[source]

Dump a cached field to a Dynamo-friendly value

ddb_dump_field_(name)[source]

Dump a field to a Dynamo-friendly value

classmethod ddb_load_(engine, data)[source]

Load a model from DynamoDB data

delete(*args, **kwargs)[source]

Delete the model from the database

classmethod field_(name)[source]

Get Field or construct a placeholder for an undeclared field

This is used for creating scan filter constraints on fields that were not declared in the model

hk_[source]

The value of the hash key

incr_(**kwargs)[source]

Atomically increment a number value

index_pk_dict_(index_name)[source]

The primary key dict for an index, encoded for dynamo

keys_()[source]

All declared fields

loading_(*args, **kwds)[source]

Context manager to speed up object load process

mark_dirty_(name)[source]

Mark that a field is dirty

meta_ = <flywheel.model_meta.ModelMetadata object>[source]
mutate_(action, **kwargs)[source]

Atomically mutate a set

partial_loading_(*args, **kwds)[source]

For use when loading a partial object (i.e. from update_field)

persisted_[source]

True if the model exists in DynamoDB, False otherwise

pk_dict_[source]

The primary key dict, encoded for dynamo

pk_tuple_[source]

The primary key dict, encoded for dynamo

post_load_(engine)[source]

Called after model loaded from database

post_save_()[source]

Called after item is saved to database

post_save_fields_(fields)[source]

Called after update_field or update_fields

pre_save_(engine)[source]

Called before saving items

refresh(consistent=False)[source]

Overwrite model data with freshest from database

remove_(**kwargs)[source]

Atomically remove from a set

rk_[source]

The value of the range key

save(overwrite=None)[source]

Save model data to database (see also: sync)

set_ddb_val_(key, val)[source]

Decode and set a value retrieved from Dynamo

sync(*args, **kwargs)[source]

Sync model changes back to database

class flywheel.models.SetDelta[source]

Bases: object

Wrapper for an atomic change to a Dynamo set

Used to track the changes when using add_() and remove_()

add(action, value)[source]

Add another update to the delta

Parameters:

action : {‘ADD’, ‘DELETE’}

value : object

The value to add or remove

merge(other)[source]

Merge the delta with a set

Parameters:

other : set

The original set to merge the changes with