pouchdb-all-dbs
Advanced tools
Comparing version 0.1.4 to 0.1.5
{ | ||
"name": "pouchdb-all-dbs", | ||
"main": "dist/pouchdb.all-dbs.js", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"homepage": "https://github.com/nolanlawson/pouchdb-all-dbs", | ||
@@ -6,0 +6,0 @@ "authors": [ |
22
index.js
@@ -6,2 +6,16 @@ 'use strict'; | ||
var PREFIX = "db_"; | ||
function prefixed(dbName) { | ||
//A database name starting with an underscore is valid, but a document | ||
//id starting with an underscore is not in most cases. Because of | ||
//that, they're prefixed in the all dbs database. See issue #7 for | ||
//more info. | ||
return PREFIX + dbName; | ||
} | ||
function unprefixed(dbName) { | ||
return dbName.slice(PREFIX.length); | ||
} | ||
module.exports = function (Pouch) { | ||
@@ -52,2 +66,3 @@ | ||
} | ||
dbName = prefixed(dbName); | ||
init(); | ||
@@ -73,2 +88,3 @@ queue.add(function (callback) { | ||
} | ||
dbName = prefixed(dbName); | ||
init(); | ||
@@ -92,5 +108,7 @@ queue.add(function (callback) { | ||
queue.add(function (callback) { | ||
pouch.allDocs().then(function (res) { | ||
// older versions of this module didn't have prefixes, so check here | ||
var opts = {startkey: PREFIX, endkey: (PREFIX + '\uffff')}; | ||
pouch.allDocs(opts).then(function (res) { | ||
var dbs = res.rows.map(function (row) { | ||
return row.key; | ||
return unprefixed(row.key); | ||
}); | ||
@@ -97,0 +115,0 @@ callback(null, dbs); |
{ | ||
"name": "pouchdb-all-dbs", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "PouchDB allDbs plugin", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -357,3 +357,21 @@ /*jshint expr:true */ | ||
}); | ||
it('saves databases with names starting with an underscore.', function (done) { | ||
var pouchName = "_" + dbName; | ||
dbs = [pouchName]; | ||
// create db | ||
new PouchDB(pouchName, function (err) { | ||
if (err) { | ||
return done(err); | ||
} | ||
PouchDB.allDbs(function (err, allDbs) { | ||
if (err) { | ||
return done(err); | ||
} | ||
allDbs.should.deep.equal(dbs); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} |
Sorry, the diff of this file is not supported yet
730800
21131