PynamoDB icon indicating copy to clipboard operation
PynamoDB copied to clipboard

Single Table Design with PynamoDB

Open HSchmale16 opened this issue 3 years ago • 1 comments

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?

  • https://aws.amazon.com/blogs/database/amazon-dynamodb-single-table-design-using-dynamodbmapper-and-spring-boot/

HSchmale16 avatar Sep 14 '21 23:09 HSchmale16

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.

SZubarev avatar Oct 21 '21 21:10 SZubarev