Sails: Support for inserting multiple records in single insert transaction?

Created on 28 Aug 2014  路  4Comments  路  Source: balderdashy/sails

I've been going through the documentation and the issues but it's still possible that I missed this so apologies if that's the case.

I'm trying to do a single insert for multiple records. My use case is as follows:

I get a post request on Sails.js which includes an array of JSON Objects, where each object in the array needs to be inserted as a record. Right now I need to loop through the array and insert each record separately (via create). It would be ideal if I could pass an array of objects to create (instead of a single object) and it would do a single insert for multiple records (not multiple inserts).

Thank you.

Most helpful comment

.create() accepts an array.

All 4 comments

+1

I am also using a similar workaround (both in the Create and Add blueprints).

Same here. I'm currently using DynamoDb so I can easily workaround by directly calling DynamoDb's BatchWriteItem (http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html) but it's not ideal to bypass the ORM.

.create() accepts an array.

Ah, this is great! Didn't know that. Thank you!

Was this page helpful?
0 / 5 - 0 ratings