-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN | ||
const hyperdb = require('hyperdb') | ||
const inherits = require('inherits') | ||
|
||
const Status = { | ||
NEW: 'new', | ||
OPENING: 'opening', | ||
OPEN: 'open', | ||
CLOSING: 'closing', | ||
CLOSED: 'closed' | ||
} | ||
|
||
module.exports = HyperDown | ||
|
||
function HyperDown (storage, key, opts) { | ||
if (!(this instanceof HyperDown)) return new HyperDown(storage, key, opts) | ||
|
||
opts.reduce = opts.reduce || defaultReduce | ||
this._db = hyperdb(storage, key, opts) | ||
this.status = Status.NEW | ||
|
||
AbstractLevelDOWN.call(this, location) | ||
} | ||
inherits(HyperDown, AbstractLevelDOWN) | ||
|
||
HyperDown.prototype._open = function (opts, cb) { | ||
this.status = Status.OPENING | ||
this._db.ready(err => { | ||
if (err) return cb(err) | ||
this.status = Status.OPEN | ||
return cb() | ||
}) | ||
} | ||
|
||
HyperDown.prototype._get = function (key, opts, cb) { | ||
return this._db.get(key, opts, cb) | ||
} | ||
|
||
HyperDown.prototype._put = function (key, value, opts, cb) { | ||
return this._db.put(key, value, cb) | ||
} | ||
|
||
HyperDown.prototype._del = function (key, opts, cb) { | ||
return this._db.del(key, cb) | ||
} | ||
|
||
HyperDown.prototype._batch = function (array, opts, cb) { | ||
return this._db.batch(array, cb) | ||
} | ||
|
||
HyperDown.prototype._iterator = function (opts) { | ||
return this._db.iterator(opts) | ||
} | ||
|
||
HyperDown.prototype.status = function () { | ||
return this.status | ||
} | ||
|
||
function defaultReduce (nodes) { | ||
if (!nodes || !nodes.length) return null | ||
return nodes[0] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "hyperdbdown", | ||
"version": "1.0.0", | ||
"description": "A levelDOWN-compliant backend based on HyperDB", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node test/all.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/andrewosh/hyperdbDOWN.git" | ||
}, | ||
"keywords": [ | ||
"leveldown", | ||
"hyperdb" | ||
], | ||
"author": "Andrew Osheroff <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/andrewosh/hyperdbDOWN/issues" | ||
}, | ||
"homepage": "https://github.com/andrewosh/hyperdbDOWN#readme", | ||
"devDependencies": { | ||
"hyperdb": "^2.1.0", | ||
"ram": "0.0.3", | ||
"standard": "^10.0.3", | ||
"tape": "^4.8.0" | ||
}, | ||
"dependencies": { | ||
"abstract-leveldown": "^4.0.2", | ||
"inherits": "^2.0.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const test = require('tape') | ||
const leveldown = require('..') | ||
const abstract = require('abstract-leveldown/abstract/get-test') | ||
|
||
abstract.all(leveldown, test) |