dynamode icon indicating copy to clipboard operation
dynamode copied to clipboard

[FEATURE] Overriding partitionKey Prefix in Single Table Design

Open gmreburn opened this issue 6 months ago • 14 comments

Summary:

I am struggling to implement multiple inheritance for classes while overriding the partitionKey's prefix in a single table design. The base table should define the partition key (pk) without any prefix, and each derived class should override it to add a specific prefix/suffix. I couldn't find any relevant guidance in the documentation. The alternative of defining each class without inheritance seems cumbersome.

Any suggestions on how to achieve this?

Code sample:

export default class Table extends Entity {
  // @attribute.partitionKey.string()
  pk: string;
}
export default class UserModel extends Table {
  @attribute.partitionKey.string({ prefix: "USER" })
  pk: string;
}
[ValidationError]: Attribute "pk" should be decorated in "n" Entity.
// Uncomment the partionKey in Table class, you get this error:
[DynamodeStorageError]: Attribute "pk" was already decorated in entity "d"

Other:

  • [x] I have read through the Dynamode documentation before posting this issue
  • [x] I have searched through the GitHub issues (including closed issues) and pull requests to ensure this feature has not already been suggested before

gmreburn avatar Jul 28 '24 16:07 gmreburn