Skip to content

Commit b632653

Browse files
authored
Merge pull request #11 from e-e-e/Frando-pass-db
Frando pass db
2 parents ac61d77 + 9d38a8e commit b632653

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ const PassThrough = stream.PassThrough
2020
function Graph (storage, key, opts) {
2121
if (!(this instanceof Graph)) return new Graph(storage, key, opts)
2222
events.EventEmitter.call(this)
23-
2423
if (typeof key === 'string') key = Buffer.from(key, 'hex')
2524

2625
if (!Buffer.isBuffer(key) && !opts) {
2726
opts = key
2827
key = null
2928
}
3029

31-
if (!opts) opts = {}
32-
this.db = hyperdb(storage, key, opts)
30+
opts = opts || {}
31+
this.db = (storage instanceof hyperdb) ? storage : hyperdb(storage, key, opts)
3332
this._prefixes = Object.assign({}, opts.prefixes || constants.DEFAULT_PREFIXES)
3433
this._basename = opts.name || constants.DEFAULT_BASE
3534
this._prefixes._ = this._basename

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ db.put(triple, function (err) {
3939

4040
Returns an instance of hyper-graph-db. Arguments are passed directly to hyperdb, look at its constructor [API](https://github.com/mafintosh/hyperdb#var-db--hyperdbstorage-key-options) for configuration options.
4141

42+
Storage argument can be a Hyperdb instance, a filepath, or a storage object. For an example of storage type objects look at [dat-storage](https://github.com/datproject/dat-storage).
43+
4244
Extra Options:
4345
```js
4446
{

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)