haseebnqureshi / serverless-hq

Serverless made quick & easy. This is your home base for quick & powerfully easy scaffolding for your next Serverless project.
MIT License
10 stars 1 forks source link

Add CreateOnce.js into DynamoDB modeling #10

Open haseebnqureshi opened 7 years ago

haseebnqureshi commented 7 years ago

By default, let's assume users will only want items with similar or the same properties, only once. We should have a data modeling method that only creates that item once.

We'll need to allow options to user to select which key/values they'd want to atomize their items.

haseebnqureshi commented 7 years ago

This gets more interesting when you're not hashing a random UUID, but instead a username, password, or any other field.

Probably want to dynamically set the main hash, and then run find or create against that one parameter.

haseebnqureshi commented 7 years ago

Best way to accomplish this is with ExpressionAttributeValues and ConditionExpression:

ExpressionAttributeValues: { :email: item.email }, ConditionExpression: "Email = :email"

This isn't critical right now for 0.3.0; currently recommend users query, then handle conditional create in handler.