dql.models module

Data containers

class dql.models.GlobalIndex(name, index_type, status, hash_key, range_key, read_throughput, write_throughput, size, includes=None, description=None)[source]

Bases: object

Container for global index data

classmethod from_description(cls, description, attrs)[source]

Create an object from a dynamo3 response

pformat(self, consumed_capacity=None)[source]

Pretty format for insertion into table pformat

schema[source]

The DQL fragment for constructing this index

class dql.models.IndexField(name, data_type, index_type, index_name, includes=None)[source]

Bases: dql.models.TableField

A TableField that is also part of a Local Secondary Index

schema[source]

The DQL syntax for creating this item

class dql.models.QueryIndex(name, is_global, hash_key, range_key, attributes=None)[source]

Bases: object

A representation of global/local indexes that used during query building.

When building queries, we need to detect if the constraints are sufficient to perform a query or if they can only do a scan. This simple container class was specifically create to make that logic simpler.

classmethod from_table_index(cls, table, index)[source]

Factory method

projects_all_attributes(self, attrs)[source]

Return True if the index projects all the attributes

scannable[source]

Only global indexes can be scanned

class dql.models.TableField(name, data_type, key_type=None)[source]

Bases: object

A DynamoDB table attribute

Parameters:
name : str
data_type : str

The type of object (e.g. ‘STRING’, ‘NUMBER’, etc)

key_type : str, optional

The type of key (e.g. ‘RANGE’, ‘HASH’, ‘INDEX’)

index_name : str, optional

If the key_type is ‘INDEX’, this will be the name of the index that uses the field as a range key.

schema[source]

The DQL syntax for creating this item

to_index(self, index_type, index_name, includes=None)[source]

Create an index field from this field

class dql.models.TableMeta(table, attrs, global_indexes, read_throughput, write_throughput, decreases_today, size)[source]

Bases: object

Container for table metadata

Parameters:
name : str
status : str
attrs : dict

Mapping of attribute name to TableField

global_indexes : dict

Mapping of hash key to GlobalIndex

read_throughput : int
write_throughput : int
decreases_today : int
size : int

Size of the table in bytes

item_count : int

Number of items in the table

classmethod from_description(cls, table)[source]

Factory method that uses the dynamo3 ‘describe’ return value

get_index(self, index_name)[source]

Get a specific index by name

get_indexes(self)[source]

Get a dict of index names to index

get_matching_indexes(self, possible_hash, possible_range)[source]

Get all indexes that could be queried on using a set of keys.

If any indexes match both hash AND range keys, indexes that only match the hash key will be excluded from the result.

Parameters:
possible_hash : set

The names of fields that could be used as the hash key

possible_range : set

The names of fields that could be used as the range key

iter_query_indexes(self)[source]

Iterator that constructs QueryIndex for all global and local indexes, and a special one for the default table hash & range key with the name ‘TABLE’

pformat(self)[source]

Pretty string format

primary_key(self, hkey, rkey=None)[source]

Construct a primary key dictionary

You can either pass in a (hash_key[, range_key]) as the arguments, or you may pass in an Item itself

primary_key_attributes[source]

Get the names of the primary key attributes as a tuple

primary_key_tuple(self, item)[source]

Get the primary key tuple from an item

schema[source]

The DQL query that will construct this table’s schema

total_read_throughput[source]

Combined read throughput of table and global indexes

total_write_throughput[source]

Combined write throughput of table and global indexes

dql.models.format_throughput(available, used=None)[source]

Format the read/write throughput for display