softprops / dynomite

⚡🦀 🧨 make your rust types fit DynamoDB and visa versa
https://docs.rs/dynomite/
MIT License
220 stars 53 forks source link

Add partition/sort key getters to Item trait #146

Open ramosbugs opened 3 years ago

ramosbugs commented 3 years ago

What did you implement:

The Item trait currently includes a key() method that returns a map from attribute name to attribute value for either the partition key only or both the partition and sort keys. In the latter case, it's not possible to distinguish between the partition and sort key attributes without separate knowledge about which key is which.

This PR adds partition_key() and sort_key() methods to the Item trait, which allow each key to be accessed separately. This makes it easier to write middleware and other generic code that works on multiple item types. Both methods are automatically implemented by the derive proc macro.

How did you verify your change:

Added some test cases, plus tested the code manually from my (separate) downstream crate.

What (if anything) would need to be called out in the CHANGELOG for the next release:

Since this PR adds new methods to the Item trait without providing a default implementation, it constitutes a breaking change for users that manually implement this trait rather than using the derive proc macro.

phrohdoh commented 3 years ago

Would you please rebase this on top of current master to address CI issues unrelated to this PR (which have since been fixed)?

zamazan4ik commented 3 years ago

@ramosbugs I've added your PR in this fork: https://github.com/rust-serverless/dynomite/commit/bad13f5822461987ca18fdc7120945947947e578

If you have any additional ideas/issues/PR - please send them in the fork above since this repo is not actively maintained by the original author.