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

Function queryPromised

lib/index.es.js:9076–9146  ·  view source on GitHub ↗
(db, fun, opts)

Source from the content-addressed store, hash-verified

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

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…