liekodb 0.1.8 → 0.1.9

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/liekodb.js +18 -5
  2. package/package.json +1 -1
package/liekodb.js CHANGED
@@ -1196,8 +1196,11 @@ class LocalAdapter {
1196
1196
  }
1197
1197
  }
1198
1198
 
1199
- async insert({ documents }) {
1199
+ async insert({ documents, options = {} } = {}) {
1200
1200
  const start = Utils.startTimer();
1201
+ const returnType = options.returnType || 'count';
1202
+ const maxReturn = options.maxReturn ?? 50;
1203
+
1201
1204
  try {
1202
1205
  const documentsToInsert = Array.isArray(documents) ? documents : [documents];
1203
1206
  const now = new Date().toISOString();
@@ -1273,6 +1276,12 @@ class LocalAdapter {
1273
1276
  totalDocuments: totalDocuments + inserted.length
1274
1277
  };
1275
1278
 
1279
+ if (returnType === 'documents' && inserted.length > 0) {
1280
+ const returnLimit = Math.min(inserted.length, maxReturn);
1281
+ const returnedDocuments = inserted.slice(0, returnLimit);
1282
+ responseData.insertedDocuments = returnedDocuments;
1283
+ }
1284
+
1276
1285
  if (inserted.length > 0) {
1277
1286
  if (inserted.length > 20) {
1278
1287
  responseData.firstId = inserted[0].id;
@@ -1284,8 +1293,9 @@ class LocalAdapter {
1284
1293
 
1285
1294
  const duration = Utils.endTimer(start);
1286
1295
  const details = updated.length > 0
1287
- ? `Inserted: ${inserted.length}, Updated: ${updated.length}`
1288
- : `Inserted: ${inserted.length}`;
1296
+ ? `Inserted: ${inserted.length}, Updated: ${updated.length} | ReturnType: ${returnType}`
1297
+ : `Inserted: ${inserted.length} | ReturnType: ${returnType}`;
1298
+
1289
1299
  this.logRequest('insert', details, duration, Utils.getDataSize(responseData));
1290
1300
 
1291
1301
  return { data: responseData };
@@ -1661,9 +1671,12 @@ class Collection {
1661
1671
  }
1662
1672
  }
1663
1673
 
1664
- async insert(documents) {
1674
+ async insert(documents, options = {}) {
1675
+ Validator.validateOptions(options);
1676
+
1665
1677
  return this.adapter.request('POST', `/collections/${encodeURIComponent(this.collectionName)}`, {
1666
- documents
1678
+ documents,
1679
+ options
1667
1680
  });
1668
1681
  }
1669
1682
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "liekodb",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/eiwSrvt/liekodb"