From 25e9ffb4384b4fbefe22ad491c2bc7c0e0e4f8ff Mon Sep 17 00:00:00 2001 From: Nathan LaFreniere Date: Mon, 30 Jun 2014 11:47:08 -0700 Subject: [PATCH] allow extra values in get/put callbacks This is mostly to facilitate RiakDOWN, since tracking vclocks manually is sometimes desirable. This will allow the _put method in abstract-leveldown backends to pass a value out to the client, and the _get method to pass extra metadata as well. --- lib/levelup.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/levelup.js b/lib/levelup.js index 22b6721e..63939eb6 100644 --- a/lib/levelup.js +++ b/lib/levelup.js @@ -186,7 +186,7 @@ LevelUP.prototype.get = function (key_, options, callback) { options.asBuffer = util.isValueAsBuffer(options) - this.db.get(key, options, function (err, value) { + this.db.get(key, options, function (err, value, extra) { if (err) { if ((/notfound/i).test(err)) { err = new NotFoundError( @@ -202,7 +202,7 @@ LevelUP.prototype.get = function (key_, options, callback) { } catch (e) { return callback(new EncodingError(e)) } - callback(null, value) + callback(null, value, extra) } }) } @@ -235,13 +235,13 @@ LevelUP.prototype.put = function (key_, value_, options, callback) { key = util.encodeKey(key_, options) value = util.encodeValue(value_, options) - this.db.put(key, value, options, function (err) { + this.db.put(key, value, options, function (err, extra) { if (err) { return dispatchError(self, new WriteError(err), callback) } else { - self.emit('put', key_, value_) + self.emit('put', key_, value_, extra) if (callback) - callback() + callback(null, extra) } }) }