clarkie / dynogels

DynamoDB data mapper for node.js. Originally forked from https://github.com/ryanfitz/vogels
Other
491 stars 110 forks source link

A method which returns the raw DynamoDB params for creating an item #172

Open aneilbaboo opened 5 years ago

aneilbaboo commented 5 years ago

This is a feature proposal to add a new function Table.prototype.createParams which will return the validated, processed parameters required to create the item using the DynamoDB API. It would behave like this:

const item = new MyItem({....});
item.createParams((err, params) => {
   // params have been validated by schema and processed by `create` hook 
   // do something with params
});

Why

AWS Data Pipeline provides a helpful solution for the hard-ish problem of bulk loading data into DynamoDB. It reads JSON files from S3 and throttles the rate at which data is written to DynamoDB.

References:

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBPipeline.html

http://eng.hakopako.net/entry/2016/08/22/100000

It would be nice to use Dynogels models schema validation and data processing to generate the required JSON.

Proposal

I think this should be straightforward. Look here in internals.createItem in table.js. I think we just want to return params without calling sendRequest.

So, here is what I'm proposing, specifically. I'd be willing to take a crack at it if it's acceptable.

  1. Separate the code in internals.createItem before sendRequest into a new function internals.makeCreateItemParams, and call this inside internals.createItem
  2. Add a new function Table.prototype.createParams() which returns the value from internals.makeCreateItemParams

(Maybe do the same for updateItem and deleteItem too).