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

Function httpQuery

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

Source from the content-addressed store, hash-verified

8279 }
8280
8281 async function httpQuery(db, fun, opts) {
8282 // List of parameters to add to the PUT request
8283 let params = [];
8284 let body;
8285 let method = 'GET';
8286 let ok;
8287
8288 // If opts.reduce exists and is defined, then add it to the list
8289 // of parameters.
8290 // If reduce=false then the results are that of only the map function
8291 // not the final result of map and reduce.
8292 addHttpParam('reduce', opts, params);
8293 addHttpParam('include_docs', opts, params);
8294 addHttpParam('attachments', opts, params);
8295 addHttpParam('limit', opts, params);
8296 addHttpParam('descending', opts, params);
8297 addHttpParam('group', opts, params);
8298 addHttpParam('group_level', opts, params);
8299 addHttpParam('skip', opts, params);
8300 addHttpParam('stale', opts, params);
8301 addHttpParam('conflicts', opts, params);
8302 addHttpParam('startkey', opts, params, true);
8303 addHttpParam('start_key', opts, params, true);
8304 addHttpParam('endkey', opts, params, true);
8305 addHttpParam('end_key', opts, params, true);
8306 addHttpParam('inclusive_end', opts, params);
8307 addHttpParam('key', opts, params, true);
8308 addHttpParam('update_seq', opts, params);
8309
8310 // Format the list of parameters into a valid URI query string
8311 params = params.join('&');
8312 params = params === '' ? '' : '?' + params;
8313
8314 // If keys are supplied, issue a POST to circumvent GET query string limits
8315 // see http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options
8316 if (typeof opts.keys !== 'undefined') {
8317 const MAX_URL_LENGTH = 2000;
8318 // according to http://stackoverflow.com/a/417184/680742,
8319 // the de facto URL length limit is 2000 characters
8320
8321 const keysAsString = `keys=${encodeURIComponent(JSON.stringify(opts.keys))}`;
8322 if (keysAsString.length + params.length + 1 <= MAX_URL_LENGTH) {
8323 // If the keys are short enough, do a GET. we do this to work around
8324 // Safari not understanding 304s on POSTs (see pouchdb/pouchdb#1239)
8325 params += (params[0] === '?' ? '&' : '?') + keysAsString;
8326 } else {
8327 method = 'POST';
8328 if (typeof fun === 'string') {
8329 body = {keys: opts.keys};
8330 } else { // fun is {map : mapfun}, so append to this
8331 fun.keys = opts.keys;
8332 }
8333 }
8334 }
8335
8336 // We are referencing a query defined in the design doc
8337 if (typeof fun === 'string') {
8338 const parts = parseViewName(fun);

Callers 1

queryPromisedFunction · 0.70

Calls 5

addHttpParamFunction · 0.70
parseViewNameFunction · 0.70
postprocessAttachmentsFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…