flywheel.model_meta module¶
Model metadata and metaclass objects
- class flywheel.model_meta.ModelMetaclass(name, bases, dct)[source]¶
Bases: type
Metaclass for Model objects
Merges model metadata, sets the meta_ attribute, and performs validation checks.
- class flywheel.model_meta.ModelMetadata(model)[source]¶
Bases: object
Container for model metadata
Parameters: model : Model Attributes
abstract Getter for abstract name (str) The unique name of the model. This is set by the ‘_name’ field in __metadata__. Defaults to the name of the model class. global_indexes (list) List of global indexes (hash_key, [range_key]) pairs. related_fields (dict) Mapping of field names to set of fields that change when that field changes (usually just that field name, but can be more if composite fields use it) orderings (list) List of Ordering throughput (dict) Mapping of ‘read’ and ‘write’ to the table throughput (default 5, 5) - create_dynamo_schema(connection, tablenames=None, test=False, wait=False, throughput=None, namespace=())[source]¶
Create all Dynamo tables for this model
Parameters: connection : DynamoDBConnection
tablenames : list, optional
List of tables that already exist. Will call ‘describe’ if not provided.
test : bool, optional
If True, don’t actually create the table (default False)
wait : bool, optional
If True, block until table has been created (default False)
throughput : dict, optional
The throughput of the table and global indexes. Has the keys ‘read’ and ‘write’. To specify throughput for global indexes, add the name of the index as a key and another ‘read’, ‘write’ dict as the value.
namespace : tuple, optional
The namespace of the table
Returns: table : str
Table name that was created, or None if nothing created
- ddb_tablename(namespace=())[source]¶
The name of the DynamoDB table
Parameters: namespace : list or str, optional
String prefix or list of component parts of a prefix for the table name. The prefix will be this string or strings (joined by ‘-‘).
- delete_dynamo_schema(connection, tablenames=None, test=False, wait=False, namespace=())[source]¶
Drop all Dynamo tables for this model
Parameters: connection : DynamoDBConnection
tablenames : list, optional
List of tables that already exist. Will call ‘describe’ if not provided.
test : bool, optional
If True, don’t actually delete the table (default False)
wait : bool, optional
If True, block until table has been deleted (default False)
namespace : tuple, optional
The namespace of the table
Returns: table : str
Table name that was deleted, or None if nothing deleted
- get_ordering_from_fields(eq_fields, fields)[source]¶
Get a unique ordering from constraint fields
Parameters: eq_fields : list
List of field names that are constrained with ‘=’.
fields : list
List of field names that are constrained with inequality operators (‘>’, ‘<’, ‘beginswith’, etc)
Returns: ordering : Ordering
Raises: exc : TypeError
If more than one possible Ordering is found
- class flywheel.model_meta.Ordering(meta, hash_key, range_key=None, index_name=None)[source]¶
Bases: object
A way that the models are ordered
This will be a combination of a hash key and a range key. It may be the primary key, a local secondary index, or a global secondary index.
- exception flywheel.model_meta.ValidationError[source]¶
Bases: exceptions.Exception
Model inconsistency