Skip to content

Commit

Permalink
First pass
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewosh committed Apr 19, 2018
1 parent f1c3d6a commit 3a6054c
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
62 changes: 62 additions & 0 deletions index.js
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]
}
33 changes: 33 additions & 0 deletions package.json
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"
}
}
5 changes: 5 additions & 0 deletions test/all.js
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)

0 comments on commit 3a6054c

Please sign in to comment.