tywalch / electrodb

A DynamoDB library to ease the use of modeling complex hierarchical relationships and implementing a Single Table Design while keeping your query code readable.
MIT License
997 stars 63 forks source link

Feature Request? Query by > 1 partition key values. #387

Closed patrickquigley102 closed 4 months ago

patrickquigley102 commented 4 months ago

Hey :wave:

My little tech company has adapted this library for our in-house serverless framework, so we've currently ~15 engineers learning this library. And it's in use in Production. We like it, thank you for making it.

I've read all previous issues, all the docs and I'm not sure if my request is currently a supported feature. I also read the discussions.

I'm new to the library and DynamoDB, so may have missed the obvious.

I would like to be able to use ElectroDB to query DynamoDB with multiple partition query values. Here is a playground illustrating what I mean.

Also in brief it'd look something like this.

Entity.query(partition_keys: ['uid1', 'uid2'])

I know this is a supported feature of DynamoDB, as I've working examples in both NoSQLWorkbench and in the AWS Console. Which I can share validation of if needed but will omit for now, beyond the PartiQL statement.

select * from "table" where "partition_key" in ['uid1', 'uid2']

Thanks for your time.

P.S. Treat yourself to a breakfast pastry, you deserve it.

tywalch commented 4 months ago

Hey @patrickquigley102 👋

Great question, and I am glad you have found the library so helpful!

The short of the long is that it is not currently a feature because it is not an available operation via the DymamoDB DocumentClient. Ultimately it could be a feature, though behind the scenes it would ultimately be syntactic sugar for multiple requests. I suspect that is also what the SQL you shared is also doing when it's exectuted.

That said, not to leave you empty handed, here is how I would begin to implement something like that. The difficultly with abstracting away multiple calls is that you have to start making hard decisions around pagination, handling partial failures, ordering, and more. That's is usually why I try to keep ElectroDB out of the business of making decisions for the user on when to make more than one request; what is helpful for one use-case can be a total arm-bar to another use-case.

Let me know if this helps!

patrickquigley102 commented 4 months ago

Hey.

Thanks for the information :slightly_smiling_face:. That's helpful.

start making hard decisions around pagination, handling partial failures, ordering, and more.

Aye, this is what I fear. And was hoping you'd already done it :joy:.

And it makes sense to keep it out of ElectroDB,.

I'll likely redesign the single table to meet the access patterns within ElectroDB's features. or change the requirements to fit the current limitation I've built.