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

Support PouchDB v6.x #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 14 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,23 @@ exports.getDiskSize = function (callback) {

if (db.type() === 'leveldb') {
var prefix = db.__opts.prefix || '';
var path = prefix + db._db_name;
var path = prefix + db.name;

// wait until the database is ready. Necessary for at least sqldown,
// which doesn't write anything to disk sooner.
var then = db.then || function (cb) {
return cb();
};
promise = then.call(db, function () {
return getSize(path);
});
if (!db.taskqueue.isReady) {
promise = new Promise(function (resolve, reject) {
db.taskqueue.addTask(function (failed) {
if (failed) {
reject(failed);
} else {
getSize(path).then(resolve, reject);
}
});
});
} else {
promise = getSize(path);
}
} else {
var msg = "Can't get the database size for database type '" + db.type() + "'!";
promise = Promise.reject(new Error(msg));
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
},
"devDependencies": {
"chai": "^3.5.0",
"fs-extra": "^0.30.0",
"fs-extra": "^2.0.0",
"istanbul": "^0.4.2",
"jshint": "^2.5.10",
"jsondown": "^0.1.1",
"locket": "1.0.0",
"medeadown": "^1.1.1",
"memdown": "^1.0.0",
"mocha": "^2.0.1",
"pouchdb": "^5.2.1",
"mocha": "^3.2.0",
"pouchdb": "^6.1.1",
"sqldown": "^2.1.0",
"sqlite3": "^3.0.4"
},
Expand Down
18 changes: 18 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,22 @@ describe('pouchdb-size tests', function () {
done();
});
});

it("should fail when adapter fails", function (done) {
var faildown = function () {
return {
open: function (opts, callback) {
callback("eww");
}
};
};
var db = new PouchDB("i", {db: faildown});

db.getDiskSize(function (err, size) {
err.should.exist;
err.message.should.equal("eww");
should.not.exist(size);
done();
});
});
});