Skip to content

Commit 6cd0417

Browse files
author
Benjamin Forster
committed
first steps towards hyperdb v3
1 parent 6f6b1ea commit 6cd0417

5 files changed

Lines changed: 17 additions & 16 deletions

File tree

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ const Transform = stream.Transform
1919
const PassThrough = stream.PassThrough
2020

2121
// temporarily augment hyperdb prototype to include createReadStream
22-
if (!hyperdb.createReadStream) {
23-
attachCreateReadStream(hyperdb)
24-
}
22+
// if (!hyperdb.createReadStream) {
23+
// console.log('USING CUSTOM createReadStream')
24+
// attachCreateReadStream(hyperdb)
25+
// }
2526

2627
function Graph (storage, key, opts) {
2728
if (!(this instanceof Graph)) return new Graph(storage, key, opts)
@@ -131,7 +132,7 @@ Graph.prototype.v = (name) => new Variable(name)
131132
function returnValueAsString (cb) {
132133
return (err, nodes) => {
133134
if (err) return cb(err)
134-
if (!nodes) return cb(null, null)
135+
if (!nodes || nodes.length === 0) return cb(null, null)
135136
cb(null, nodes[0].value.toString())
136137
}
137138
}

lib/HyperdbReadTransform.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ const utils = require('./utils')
44

55
function HyperdbReadTransform (db, basename, options) {
66
if (!(this instanceof HyperdbReadTransform)) {
7-
return new HyperdbReadTransform(db, options)
7+
return new HyperdbReadTransform(db, basename, options)
88
}
99
var opts = options || {}
1010
this.db = db
1111
this._prefixes = { _: basename }
12-
this._finished = false
1312
this._count = 0
1413
this._filter = opts.filter
1514
this._offset = opts.offset || 0
@@ -25,13 +24,6 @@ function HyperdbReadTransform (db, basename, options) {
2524
inherits(HyperdbReadTransform, Transform)
2625

2726
HyperdbReadTransform.prototype._transform = function transform (nodes, encoding, done) {
28-
if (this._finished) return done()
29-
if (this._limit && this._count >= this._limit) {
30-
this.push(null)
31-
this._sources.forEach(source => source.destroy())
32-
this._finished = true
33-
return
34-
}
3527
var value = nodes[0].value && JSON.parse(nodes[0].value.toString())
3628
if (value === null) return done()
3729
value = Object.assign(value, utils.decodeKey(nodes[0].key, this._prefixes))
@@ -40,8 +32,16 @@ HyperdbReadTransform.prototype._transform = function transform (nodes, encoding,
4032
this.push(value)
4133
}
4234
this._count++
35+
if (this._limit && this._count >= this._limit) {
36+
this.end()
37+
}
4338
}
4439
done()
4540
}
4641

42+
HyperdbReadTransform.prototype._flush = function (done) {
43+
this._sources.forEach(source => source.destroy())
44+
done()
45+
}
46+
4747
module.exports = HyperdbReadTransform

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const tripleAliasMap = {
1010
}
1111

1212
function isNewDatabase (db) {
13-
return !(db._writers.length > 1 || db._writers[0].feed.length > 0)
13+
return !(db.feeds.length > 1 || db.feeds[0].length > 0)
1414
}
1515

1616
function put (db, data, callback) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"url": "https://github.com/e-e-e/hyper-graph-db/issues"
1212
},
1313
"dependencies": {
14-
"hyperdb": "^2.0.0",
14+
"hyperdb": "3.0.0-0",
1515
"lru": "^3.1.0",
1616
"pump": "^3.0.0",
1717
"readable-stream": "^2.3.3",

test/basic.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ describe('hypergraph', function () {
136136
db = hypergraph(dbDir)
137137
db.on('ready', () => {
138138
db.db.get('@version', (err, nodes) => {
139-
expect(nodes).to.eql(null)
139+
expect(nodes).to.eql([])
140140
finish(err)
141141
})
142142
})

0 commit comments

Comments
 (0)