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: - 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.
abstract
: boolGetter for abstract
- 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 : str or tuple, optional
The namespace of the table
Returns: - table : str
Table name that was created, or None if nothing created
- connection :
-
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 : str or tuple, optional
The namespace of the table
Returns: - table : str
Table name that was deleted, or None if nothing deleted
- connection :
-
get_ordering_from_fields
(eq_fields, fields)[source]¶ Get a unique ordering from constraint fields.
This does a best-effort guess of which index is being queried. It prioritizes indexes that have a constraint on the range key. It prioritizes the primary key over local and global indexes.
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
-
index_pk_dict
(index_name, obj=None, scope=None, ddb_dump=False)[source]¶ Get the primary key dict for an index (includes the table key)
-
pk_tuple
(obj=None, scope=None, ddb_dump=False, ddb_load=False)[source]¶ Get a tuple that represents the primary key for an item
-
update_dynamo_schema
(connection, test=False, wait=False, throughput=None, namespace=())[source]¶ Updates all Dynamo table global indexes for this model
Parameters: - connection :
DynamoDBConnection
- 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 : str or tuple, optional
The namespace of the table
Returns: - table : str
Table name that altered, or None if nothing altered
- connection :
- model :
-
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.