couchbase-driver
Advanced tools
Comparing version 0.1.8 to 0.1.10-0
@@ -48,2 +48,3 @@ 'use strict'; | ||
atomicRetryInterval: 0, | ||
atomicLock: true, | ||
missing: true | ||
@@ -291,2 +292,21 @@ }; | ||
value: function atomic(key, transform) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var fn = arguments.length <= 3 || arguments[3] === undefined ? _lodash2.default.noop : arguments[3]; | ||
if (options instanceof Function) { | ||
fn = options; | ||
options = {}; | ||
} | ||
var retryOptions = _lodash2.default.defaults(options, this.config); | ||
debug('Driver.atomic. key: ' + key); | ||
if (options.atomicLock) { | ||
return this.atomicWithLock(key, transform, options, fn); | ||
} | ||
return this.atomicNoLock(key, transform, options, fn); | ||
} | ||
}, { | ||
key: 'atomicWithLock', | ||
value: function atomicWithLock(key, transform) { | ||
var _this2 = this; | ||
@@ -304,3 +324,3 @@ | ||
debug('Driver.atomic. key: ' + key); | ||
debug('Driver.atomicWithLock. key: ' + key); | ||
_async2.default.retry(retryOptions, function (rfn) { | ||
@@ -314,3 +334,3 @@ _this2.getAndLock(key, function (err, doc) { | ||
var opts = doc ? { cas: doc.cas } : {}; | ||
debug('Driver.atomic. action: ' + opr.action); | ||
debug('Driver.atomicWithLock. action: ' + opr.action); | ||
if (opr.action === OPERATIONS.NOOP) { | ||
@@ -337,3 +357,36 @@ if (!doc) { | ||
} | ||
}, { | ||
key: 'atomicNoLock', | ||
value: function atomicNoLock(key, transform) { | ||
var _this3 = this; | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var fn = arguments.length <= 3 || arguments[3] === undefined ? _lodash2.default.noop : arguments[3]; | ||
if (options instanceof Function) { | ||
fn = options; | ||
options = {}; | ||
} | ||
var retryOptions = _lodash2.default.defaults(options, this.config); | ||
_async2.default.retry(retryOptions, function (rfn) { | ||
_this3.get(key, function (err, doc) { | ||
if (err) { | ||
return rfn(err); | ||
} | ||
var opr = transform(doc ? doc.value : undefined); | ||
var opts = doc ? { cas: doc.cas } : {}; | ||
debug('Driver.atomicNoLock. action: ' + opr.action); | ||
if (opr.action === OPERATIONS.NOOP) { | ||
return rfn(null, opr.value); | ||
} else if (opr.action === OPERATIONS.UPSERT && opr.value) { | ||
return _this3.bucket.upsert(key, opr.value, opts, rfn); | ||
} | ||
return _this3.bucket.remove(key, opts, rfn); | ||
}); | ||
}, fn); | ||
} | ||
/** | ||
@@ -340,0 +393,0 @@ * Create a Driver object by wrapping the Couchbase bucket and creates a new <code>Driver</code> instance and |
{ | ||
"name": "couchbase-driver", | ||
"description": "An improved version of the official Couchbase driver", | ||
"version": "0.1.8", | ||
"version": "0.1.10-0", | ||
"homepage": "https://github.com/bojand/couchbase-driver", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
37902
452