MCPcopy
hub / github.com/apache/pouchdb / LevelPouch

Function LevelPouch

lib/index.js:5024–6387  ·  view source on GitHub ↗
(opts, callback)

Source from the content-addressed store, hash-verified

5022}
5023
5024function LevelPouch(opts, callback) {
5025 opts = clone(opts);
5026 var api = this;
5027 var instanceId;
5028 var stores = {};
5029 var revLimit = opts.revs_limit;
5030 var db;
5031 var name = opts.name;
5032 // TODO: this is undocumented and unused probably
5033 /* istanbul ignore else */
5034 if (typeof opts.createIfMissing === 'undefined') {
5035 opts.createIfMissing = true;
5036 }
5037
5038 var leveldown = opts.db;
5039
5040 var dbStore;
5041 var leveldownName = functionName(leveldown);
5042 if (dbStores.has(leveldownName)) {
5043 dbStore = dbStores.get(leveldownName);
5044 } else {
5045 dbStore = new Map();
5046 dbStores.set(leveldownName, dbStore);
5047 }
5048 if (dbStore.has(name)) {
5049 db = dbStore.get(name);
5050 afterDBCreated();
5051 } else {
5052 dbStore.set(name, sublevelPouch(levelup(leveldown(name), opts, function (err) {
5053 /* istanbul ignore if */
5054 if (err) {
5055 dbStore.delete(name);
5056 return callback(err);
5057 }
5058 db = dbStore.get(name);
5059 db._docCount = -1;
5060 db._queue = new Deque();
5061 /* istanbul ignore else */
5062 if (typeof opts.migrate === 'object') { // migration for leveldown
5063 opts.migrate.doMigrationOne(name, db, afterDBCreated);
5064 } else {
5065 afterDBCreated();
5066 }
5067 })));
5068 }
5069
5070 function afterDBCreated() {
5071 stores.docStore = db.sublevel(DOC_STORE, {valueEncoding: safeJsonEncoding});
5072 stores.bySeqStore = db.sublevel(BY_SEQ_STORE, {valueEncoding: 'json'});
5073 stores.attachmentStore =
5074 db.sublevel(ATTACHMENT_STORE, {valueEncoding: 'json'});
5075 stores.binaryStore = db.sublevel(BINARY_STORE, {valueEncoding: 'binary'});
5076 stores.localStore = db.sublevel(LOCAL_STORE, {valueEncoding: 'json'});
5077 stores.metaStore = db.sublevel(META_STORE, {valueEncoding: 'json'});
5078 /* istanbul ignore else */
5079 if (typeof opts.migrate === 'object') { // migration for leveldown
5080 opts.migrate.doMigrationTwo(db, stores, afterLastMigration);
5081 } else {

Callers

nothing calls this directly

Calls 15

getMethod · 0.95
batchMethod · 0.95
executeMethod · 0.95
cloneFunction · 0.70
afterDBCreatedFunction · 0.70
sublevelPouchFunction · 0.70
readLockFunction · 0.70
createErrorFunction · 0.70
getWinningRevFunction · 0.70
getIsDeletedFunction · 0.70
latestFunction · 0.70
formatSeqFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…