pynamodb / PynamoDB

A pythonic interface to Amazon's DynamoDB
http://pynamodb.readthedocs.io
MIT License
2.46k stars 427 forks source link

Single Table Design with PynamoDB #977

Open HSchmale16 opened 3 years ago

HSchmale16 commented 3 years ago

Does this library support single table design for dynamodb? I've read a couple blog posts and now I'm intrigued about it.

It's where you store items of different types in the same table, and use the hash key differentiate them. For instance in the blog post below, they have ski lift time series information for a given object stored as the instance identifier in the hash key and the various attributes defined in the sort key.

It looks like they define getters to override what should be returned for a given attribute.

Would it be possible to do something similar with pynamodb? What are some best practices if it's possible?

SZubarev commented 3 years ago

Yes it does, at least I'm using it for storing multiple entities in one table and all works great. I created an abstract SingleTableBase class which holds my common attributes, discriminator attribute, and I inherited my other classes from it. For each class I specified a unique "discriminator" which PynamoDB uses to instantiate specific child classes.