@pi-r/mongodb 0.12.5 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/client/index.js +10 -5
  2. package/package.json +1 -1
package/client/index.js CHANGED
@@ -331,9 +331,10 @@ async function executeBatchQuery(batch, options = '', outResult) {
331
331
  }
332
332
  let queryString = '', cacheCredential, rows, pipeline;
333
333
  if (caching && ignoreCache !== true && !streamRow) {
334
- const collection = item.client?.collection;
335
- const db = item.client?.db;
336
- queryString = (name || '') + '_' + table + (item.withFields ? '_' + Db.asString(item.withFields, true) : '') + (sort ? '_' + Db.asString(sort, true) : '') + '_' + (limit > 0 ? limit.toString() : '0') + (db ? Db.asString(db, true) : '') + (collection ? Db.asString(collection, true) : '') + (targetObject && typeof item.cacheObjectKey === 'string' ? targetObject.toString() + item.cacheObjectKey : '');
334
+ queryString = Db.keyForResult(name, table, item.withFields, sort, Math.max(0, limit));
335
+ if (item.client) {
336
+ queryString = Db.keyForResult(queryString, item.client.db, item.client.collection);
337
+ }
337
338
  }
338
339
  if (aggregate) {
339
340
  pipeline = Array.isArray(aggregate) ? aggregate : aggregate.pipeline;
@@ -345,6 +346,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
345
346
  if (queryString) {
346
347
  const setResult = () => {
347
348
  if (ignoreCache !== 1 && (rows = this.getQueryResult(source, cacheCredential, queryString, cacheValue))) {
349
+ if (targetObject) {
350
+ rows = targetObject(item, rows);
351
+ }
348
352
  ++mongoCache;
349
353
  if (parallel) {
350
354
  tasks[i] = Promise.resolve(rows);
@@ -358,7 +362,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
358
362
  return false;
359
363
  };
360
364
  if (pipeline || query || distinct) {
361
- queryString += Db.asString(aggregate || query || distinct, true);
365
+ queryString = Db.keyForResult(queryString, aggregate || query || distinct);
362
366
  cacheCredential = DbPool.sanitize(mongoCredential || credential, sortKeys);
363
367
  if ((aggregate || distinct || !update) && setResult()) {
364
368
  continue;
@@ -512,10 +516,11 @@ async function executeBatchQuery(batch, options = '', outResult) {
512
516
  }
513
517
  if (rows) {
514
518
  this.add(item, 4);
519
+ rows = this.setQueryResult(source, cacheCredential, queryString, rows, cacheValue);
515
520
  if (targetObject) {
516
521
  rows = targetObject(item, rows);
517
522
  }
518
- resolve(this.setQueryResult(source, cacheCredential, queryString, rows, cacheValue));
523
+ resolve(rows);
519
524
  }
520
525
  else {
521
526
  throw errorMessage(source, "Missing database query");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mongodb",
3
- "version": "0.12.5",
3
+ "version": "0.13.0",
4
4
  "description": "MongoDB client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",