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

Function queryPromised

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

Source from the content-addressed store, hash-verified

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

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…