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

Function init

lib/index-browser.js:5877–6627  ·  view source on GitHub ↗
(api, opts, callback)

Source from the content-addressed store, hash-verified

5875}
5876
5877function init(api, opts, callback) {
5878
5879 var dbName = opts.name;
5880
5881 var idb = null;
5882 var idbGlobalFailureError = null;
5883 api._meta = null;
5884
5885 function enrichCallbackError(callback) {
5886 return function (error, result) {
5887 if (error && error instanceof Error && !error.reason) {
5888 if (idbGlobalFailureError) {
5889 error.reason = idbGlobalFailureError;
5890 }
5891 }
5892
5893 callback(error, result);
5894 };
5895 }
5896
5897 // called when creating a fresh new database
5898 function createSchema(db) {
5899 var docStore = db.createObjectStore(DOC_STORE, {keyPath : 'id'});
5900 db.createObjectStore(BY_SEQ_STORE, {autoIncrement: true})
5901 .createIndex('_doc_id_rev', '_doc_id_rev', {unique: true});
5902 db.createObjectStore(ATTACH_STORE, {keyPath: 'digest'});
5903 db.createObjectStore(META_STORE, {keyPath: 'id', autoIncrement: false});
5904 db.createObjectStore(DETECT_BLOB_SUPPORT_STORE);
5905
5906 // added in v2
5907 docStore.createIndex('deletedOrLocal', 'deletedOrLocal', {unique : false});
5908
5909 // added in v3
5910 db.createObjectStore(LOCAL_STORE, {keyPath: '_id'});
5911
5912 // added in v4
5913 var attAndSeqStore = db.createObjectStore(ATTACH_AND_SEQ_STORE,
5914 {autoIncrement: true});
5915 attAndSeqStore.createIndex('seq', 'seq');
5916 attAndSeqStore.createIndex('digestSeq', 'digestSeq', {unique: true});
5917 }
5918
5919 // migration to version 2
5920 // unfortunately "deletedOrLocal" is a misnomer now that we no longer
5921 // store local docs in the main doc-store, but whaddyagonnado
5922 function addDeletedOrLocalIndex(txn, callback) {
5923 var docStore = txn.objectStore(DOC_STORE);
5924 docStore.createIndex('deletedOrLocal', 'deletedOrLocal', {unique : false});
5925
5926 docStore.openCursor().onsuccess = function (event) {
5927 var cursor = event.target.result;
5928 if (cursor) {
5929 var metadata = cursor.value;
5930 var deleted = isDeleted(metadata);
5931 metadata.deletedOrLocal = deleted ? "1" : "0";
5932 docStore.put(metadata);
5933 cursor.continue();
5934 } else {

Callers 1

IdbPouchFunction · 0.70

Calls 15

toPromiseFunction · 0.70
idbBulkDocsFunction · 0.70
enrichCallbackErrorFunction · 0.70
openTransactionSafelyFunction · 0.70
decodeMetadataFunction · 0.70
createErrorFunction · 0.70
finishFunction · 0.70
isDeletedFunction · 0.70
latestFunction · 0.70
decodeDocFunction · 0.70
readBlobDataFunction · 0.70
idbAllDocsFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…