Skip to content

Commit 709f62c

Browse files
chore: add db transaction
1 parent 0833de7 commit 709f62c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

slim.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ DynamoTable.prototype.update = function(key, actions, options, cb) {
144144
// If actions is a string or array, then it's a whitelist for attributes to update
145145
if (typeof actions === 'string') actions = [actions]
146146
if (Array.isArray(actions)) { pick = actions; actions = key; key = null }
147+
if (!actions) { actions = key; key = null }
147148

148149
// If key is null, assume actions has a full object to put so clone it (without keys)
149150
if (key == null) {
@@ -315,7 +316,16 @@ DynamoTable.prototype.batchGet = function(keys, options, tables, cb) {
315316

316317
// http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html
317318
DynamoTable.MAX_WRITE = 25
318-
DynamoTable.prototype.batchWrite = function(operations, tables, cb) {
319+
DynamoTable.prototype.batchWrite = function(operations, tables, options, cb) {
320+
if (!cb) {
321+
cb = options;
322+
if (Object.prototype.toString.call(tables) === '[object Object]') {
323+
options = tables;
324+
tables = [];
325+
} else {
326+
options = {}
327+
}
328+
}
319329
if (!cb) { cb = tables; tables = [] }
320330
if (typeof cb !== 'function') throw new Error('Last parameter must be a callback function')
321331
cb = once(cb)
@@ -353,7 +363,8 @@ DynamoTable.prototype.batchWrite = function(operations, tables, cb) {
353363
}
354364

355365
function batchRequest(requestItems, cb) {
356-
self.client.request('BatchWriteItem', {RequestItems: requestItems}, function(err, data) {
366+
options.RequestItems = requestItems
367+
self.client.request('BatchWriteItem', options, function(err, data) {
357368
if (err) return cb(err)
358369
if (Object.keys(data.UnprocessedItems || {}).length)
359370
return batchRequest(data.UnprocessedItems, cb)

0 commit comments

Comments
 (0)