Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix db init #95

Merged
merged 8 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ var document = require('./document')
, events = require('events')
, Cursor = require('./cursor')
, levelup = require('levelup')
, hat = require('hat')
, encode = require('encoding-down') ;

, encode = require('encoding-down')
, hat = require('hat');

var leveldown = null;
try {
leveldown = require('leveldown')
} catch (error) {

}
var stores = {}; // We have to keep those unique by filename because they're locked

var LEVELUP_RETR_CONCURRENCY = 10; // We'll use that on a bagpipe instance regulating findById
Expand Down Expand Up @@ -77,8 +83,9 @@ Model.prototype.initStore = function() {

// LevelUP ; the safety we have here to re-use instance is right now only because of the tests
this.store = stores[path.resolve(filename)];
this.store = stores[path.resolve(filename)] = (this.store && this.store.isOpen()) ? this.store : levelup(encode(this.options.store.db(filename, this.options.store || { })));

var options = this.options.store || { };
var db = options.db || leveldown;
this.store = stores[path.resolve(filename)] = (this.store && this.store.isOpen()) ? this.store : levelup(encode(db(filename), options), options);
this._pipe.resume();
};

Expand Down
Loading