Skip to content

Commit

Permalink
Re-implement iterate using extracted libraries.
Browse files Browse the repository at this point in the history
Closes #75.
  • Loading branch information
flatheadmill committed Dec 31, 2013
1 parent a9da90c commit 3f09d8e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var mkdirp = require('mkdirp')

var pair = require('pair')

function echo (object) { return object }

var mvcc = {
revise: require('revise'),
riffle: require('riffle'),
Expand All @@ -30,7 +32,7 @@ function isTrue (options, property, defaultValue) {
}

function Iterator (db, options) {
var versions = {}
var versions = {}, preferences = [ options, db._options ]

for (var key in db._versions) {
versions[key] = true
Expand All @@ -41,8 +43,10 @@ function Iterator (db, options) {
this._limit = options.limit
this._versions = versions
this._direction = isTrue(options, 'reverse', false) ? 'reverse' : 'forward'
this._keyAsBuffer = isTrue(options, 'keyAsBuffer', true)
this._valueAsBuffer = isTrue(options, 'valueAsBuffer', true)
this._decoders = {
key: isTrue(options, 'keyAsBuffer', true) ? echo : pair.encoder.key(preferences).decode,
value: isTrue(options, 'valueAsBuffer', true) ? echo : pair.encoder.value(preferences).decode
}
}
util.inherits(Iterator, AbstractIterator)

Expand Down Expand Up @@ -70,7 +74,9 @@ Iterator.prototype._next = cadence(function (step) {
}, function (iterator) {
iterator.next(step())
}, function (record) {
if (record) step(null, record.key, record.value)
if (record) {
step(null, this._decoders.key(record.key), this._decoders.value(record.value))
}
})
})

Expand Down
1 change: 1 addition & 0 deletions release.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ to build other databases.

### Issue by Issue

* Re-implement iterator using abstracted libraries. #75.
* Re-implement batch using abstracted libraries. #74.
* Re-implement delete using abstracted libraries. #73.
* Re-implement get using extracted libraries. #72.
Expand Down
File renamed without changes.

0 comments on commit 3f09d8e

Please sign in to comment.