Skip to content

Commit e71a681

Browse files
author
Benjamin Forster
committed
set hyperdb instance via storage arg
1 parent 62175b8 commit e71a681

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function Graph (storage, key, opts) {
2828
}
2929

3030
opts = opts || {}
31-
this.db = hyperdb(storage, key, opts)
31+
this.db = (storage instanceof hyperdb) ? storage : hyperdb(storage, key, opts)
3232
this._prefixes = Object.assign({}, opts.prefixes || constants.DEFAULT_PREFIXES)
3333
this._basename = opts.name || constants.DEFAULT_BASE
3434
this._prefixes._ = this._basename

test/basic.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ function ramStore (filename) {
1919

2020
describe('hypergraph', function () {
2121
let db
22+
describe('constructor storage argument', () => {
23+
context('with instance of hyperdb', () => {
24+
it('sets graph database to hyperdb passed into the constructor', () => {
25+
var hyperdbInstance = hyperdb(ramStore)
26+
db = hypergraph(hyperdbInstance)
27+
expect(db.db).to.eql(hyperdbInstance)
28+
})
29+
})
30+
})
2231
context('when newly created it adds metadata to db', () => {
2332
it('includes graph version', (done) => {
2433
db = hypergraph(ramStore)

0 commit comments

Comments
 (0)