MCPcopy Index your code
hub / github.com/apache/pouchdb / queryPromised

Function queryPromised

lib/index-browser.es.js:9039–9109  ·  view source on GitHub ↗
(db, fun, opts)

Source from the content-addressed store, hash-verified

9037 }
9038
9039 async function queryPromised(db, fun, opts) {
9040 /* istanbul ignore next */
9041 if (typeof db._query === 'function') {
9042 return customQuery(db, fun, opts);
9043 }
9044 if (isRemote(db)) {
9045 return httpQuery(db, fun, opts);
9046 }
9047
9048 const updateViewOpts = {
9049 changes_batch_size: db.__opts.view_update_changes_batch_size || CHANGES_BATCH_SIZE$1
9050 };
9051
9052 if (typeof fun !== 'string') {
9053 // temp_view
9054 checkQueryParseError(opts, fun);
9055
9056 tempViewQueue.add(async function () {
9057 const view = await createView(
9058 /* sourceDB */ db,
9059 /* viewName */ 'temp_view/temp_view',
9060 /* mapFun */ fun.map,
9061 /* reduceFun */ fun.reduce,
9062 /* temporary */ true,
9063 /* localDocName */ localDocName);
9064
9065 return fin(updateView(view, updateViewOpts).then(
9066 function () { return queryView(view, opts); }),
9067 function () { return view.db.destroy(); }
9068 );
9069 });
9070 return tempViewQueue.finish();
9071 } else {
9072 // persistent view
9073 const fullViewName = fun;
9074 const parts = parseViewName(fullViewName);
9075 const designDocName = parts[0];
9076 const viewName = parts[1];
9077
9078 const doc = await db.get('_design/' + designDocName);
9079 fun = doc.views && doc.views[viewName];
9080
9081 if (!fun) {
9082 // basic validator; it's assumed that every subclass would want this
9083 throw new NotFoundError(`ddoc ${doc._id} has no view named ${viewName}`);
9084 }
9085
9086 ddocValidator(doc, viewName);
9087 checkQueryParseError(opts, fun);
9088
9089 const view = await createView(
9090 /* sourceDB */ db,
9091 /* viewName */ fullViewName,
9092 /* mapFun */ fun.map,
9093 /* reduceFun */ fun.reduce,
9094 /* temporary */ false,
9095 /* localDocName */ localDocName);
9096

Callers 1

abstractQueryFunction · 0.70

Calls 14

customQueryFunction · 0.70
isRemoteFunction · 0.70
httpQueryFunction · 0.70
checkQueryParseErrorFunction · 0.70
createViewFunction · 0.70
finFunction · 0.70
updateViewFunction · 0.70
queryViewFunction · 0.70
parseViewNameFunction · 0.70
ddocValidatorFunction · 0.70
addMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…