@pi-r/mongodb 0.12.4 → 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 +15 -10
  2. package/package.json +5 -5
package/client/index.js CHANGED
@@ -228,9 +228,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
228
228
  if (length === 0) {
229
229
  return [];
230
230
  }
231
- let parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss;
231
+ let parallel, checkObject, connectOnce, errorQuery, errorAsEmpty, sessionKey, outCacheMiss;
232
232
  if (isPlainObject(options)) {
233
- ({ parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
233
+ ({ parallel, checkObject, connectOnce, errorQuery, errorAsEmpty, sessionKey, outCacheMiss } = options);
234
234
  }
235
235
  else {
236
236
  if (typeof options === 'string') {
@@ -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;
@@ -506,17 +510,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
506
510
  }
507
511
  })
508
512
  .on('end', () => stream.destroy());
513
+ return;
509
514
  }
510
- else {
511
- rows = await cursor.toArray();
512
- }
515
+ rows = await cursor.toArray();
513
516
  }
514
517
  if (rows) {
515
518
  this.add(item, 4);
519
+ rows = this.setQueryResult(source, cacheCredential, queryString, rows, cacheValue);
516
520
  if (targetObject) {
517
521
  rows = targetObject(item, rows);
518
522
  }
519
- resolve(this.setQueryResult(source, cacheCredential, queryString, rows, cacheValue));
523
+ resolve(rows);
520
524
  }
521
525
  else {
522
526
  throw errorMessage(source, "Missing database query");
@@ -543,6 +547,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
543
547
  }
544
548
  return this.processRows(batch, tasks, clients.length === 0 ? parallel : {
545
549
  parallel,
550
+ errorAsEmpty,
546
551
  disconnect() {
547
552
  for (const item of clients) {
548
553
  void item.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mongodb",
3
- "version": "0.12.4",
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",
@@ -17,9 +17,9 @@
17
17
  "license": "MIT",
18
18
  "homepage": "https://github.com/anpham6/pi-r#readme",
19
19
  "dependencies": {
20
- "@e-mc/db": "^0.14.5",
21
- "@e-mc/request": "^0.14.5",
22
- "@e-mc/types": "^0.14.5",
23
- "mongodb": "^7.5.0"
20
+ "@e-mc/db": "^0.14.6",
21
+ "@e-mc/request": "^0.14.6",
22
+ "@e-mc/types": "^0.14.6",
23
+ "mongodb": "^7.6.0"
24
24
  }
25
25
  }