Created
November 24, 2015 00:34
-
-
Save numberoverzero/f574086a51850324c3de to your computer and use it in GitHub Desktop.
Ideas about inheritance with declarative modeling for dynamodb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Expanded from Account in http://bloop.readthedocs.org/en/latest/ | |
class Account(engine.model): | |
class Meta: | |
abstract = True # Don't create/validate as a literal table in Dynamo | |
read_units = 100 | |
write_units = 10 | |
id = Column(UUID, hash_key=True) | |
name = Column(String) | |
email = Column(String) | |
by_email = GlobalSecondaryIndex( | |
hash_key='email', projection='keys_only', | |
write_units=1, read_units=5) | |
class GoogleAccount(Account): | |
class Meta: | |
# Implicit abstract = False | |
# tables are created unless explicitly declared as an abstract base | |
read_units = 10 | |
table_name = "accounts-goog" | |
class GooglePremiumAccount(GoogleAccount): | |
premium = Column(Boolean) | |
# Meta.table_name is inherited from the parent | |
# this has Meta.table_name = "accounts-goog" | |
class FacebookAccount(Account): | |
class Meta: | |
read_units = 200 | |
permissions = Column(Set(String)) | |
# Implict table name from class name | |
# parent has no table_name | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Single table per engine
Supporting the streaming api has a host of complications when a single table backs more than one model in an engine. How are changes populated into the correct model?
Alternatively, the engine can disallow mapping more than one model (within that engine) to a single table. That is, there will always be at most one model for a given table, through a given engine. This would require a way to watch multiple engines at once; perhaps the following signature: