MCPcopy Create free account
hub / github.com/apache/pouchdb / queryPromised

Function queryPromised

lib/index.js:9081–9151  ·  view source on GitHub ↗
(db, fun, opts)

Source from the content-addressed store, hash-verified

9079 }
9080
9081 async function queryPromised(db, fun, opts) {
9082 /* istanbul ignore next */
9083 if (typeof db._query === 'function') {
9084 return customQuery(db, fun, opts);
9085 }
9086 if (isRemote(db)) {
9087 return httpQuery(db, fun, opts);
9088 }
9089
9090 const updateViewOpts = {
9091 changes_batch_size: db.__opts.view_update_changes_batch_size || CHANGES_BATCH_SIZE$1
9092 };
9093
9094 if (typeof fun !== 'string') {
9095 // temp_view
9096 checkQueryParseError(opts, fun);
9097
9098 tempViewQueue.add(async function () {
9099 const view = await createView(
9100 /* sourceDB */ db,
9101 /* viewName */ 'temp_view/temp_view',
9102 /* mapFun */ fun.map,
9103 /* reduceFun */ fun.reduce,
9104 /* temporary */ true,
9105 /* localDocName */ localDocName);
9106
9107 return fin(updateView(view, updateViewOpts).then(
9108 function () { return queryView(view, opts); }),
9109 function () { return view.db.destroy(); }
9110 );
9111 });
9112 return tempViewQueue.finish();
9113 } else {
9114 // persistent view
9115 const fullViewName = fun;
9116 const parts = parseViewName(fullViewName);
9117 const designDocName = parts[0];
9118 const viewName = parts[1];
9119
9120 const doc = await db.get('_design/' + designDocName);
9121 fun = doc.views && doc.views[viewName];
9122
9123 if (!fun) {
9124 // basic validator; it's assumed that every subclass would want this
9125 throw new NotFoundError$1(`ddoc ${doc._id} has no view named ${viewName}`);
9126 }
9127
9128 ddocValidator(doc, viewName);
9129 checkQueryParseError(opts, fun);
9130
9131 const view = await createView(
9132 /* sourceDB */ db,
9133 /* viewName */ fullViewName,
9134 /* mapFun */ fun.map,
9135 /* reduceFun */ fun.reduce,
9136 /* temporary */ false,
9137 /* localDocName */ localDocName);
9138

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…