liekodb 0.1.7 → 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.
- package/liekodb.js +24 -7
- package/package.json +1 -1
package/liekodb.js
CHANGED
|
@@ -197,7 +197,9 @@ class CollectionCache {
|
|
|
197
197
|
data.dirty = false;
|
|
198
198
|
this.dirty.delete(name);
|
|
199
199
|
|
|
200
|
-
|
|
200
|
+
if (this.debug) {
|
|
201
|
+
console.log(`[CollectionCache] Saved ${name}.json with ${data.documents.length} documents in ${Format.formatDuration(Utils.endTimer(start))}`);
|
|
202
|
+
}
|
|
201
203
|
return true;
|
|
202
204
|
});
|
|
203
205
|
}
|
|
@@ -225,7 +227,9 @@ class CollectionCache {
|
|
|
225
227
|
|
|
226
228
|
await Promise.all(savePromises);
|
|
227
229
|
|
|
228
|
-
|
|
230
|
+
if (this.debug) {
|
|
231
|
+
console.log(`[CollectionCache] Flushed ${savePromises.length} collections in ${Format.formatDuration(Utils.endTimer(start))}`);
|
|
232
|
+
}
|
|
229
233
|
}
|
|
230
234
|
|
|
231
235
|
async shutdown(signal) {
|
|
@@ -1192,8 +1196,11 @@ class LocalAdapter {
|
|
|
1192
1196
|
}
|
|
1193
1197
|
}
|
|
1194
1198
|
|
|
1195
|
-
async insert({ documents }) {
|
|
1199
|
+
async insert({ documents, options = {} } = {}) {
|
|
1196
1200
|
const start = Utils.startTimer();
|
|
1201
|
+
const returnType = options.returnType || 'count';
|
|
1202
|
+
const maxReturn = options.maxReturn ?? 50;
|
|
1203
|
+
|
|
1197
1204
|
try {
|
|
1198
1205
|
const documentsToInsert = Array.isArray(documents) ? documents : [documents];
|
|
1199
1206
|
const now = new Date().toISOString();
|
|
@@ -1269,6 +1276,12 @@ class LocalAdapter {
|
|
|
1269
1276
|
totalDocuments: totalDocuments + inserted.length
|
|
1270
1277
|
};
|
|
1271
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
|
+
|
|
1272
1285
|
if (inserted.length > 0) {
|
|
1273
1286
|
if (inserted.length > 20) {
|
|
1274
1287
|
responseData.firstId = inserted[0].id;
|
|
@@ -1280,8 +1293,9 @@ class LocalAdapter {
|
|
|
1280
1293
|
|
|
1281
1294
|
const duration = Utils.endTimer(start);
|
|
1282
1295
|
const details = updated.length > 0
|
|
1283
|
-
? `Inserted: ${inserted.length}, Updated: ${updated.length}`
|
|
1284
|
-
: `Inserted: ${inserted.length}`;
|
|
1296
|
+
? `Inserted: ${inserted.length}, Updated: ${updated.length} | ReturnType: ${returnType}`
|
|
1297
|
+
: `Inserted: ${inserted.length} | ReturnType: ${returnType}`;
|
|
1298
|
+
|
|
1285
1299
|
this.logRequest('insert', details, duration, Utils.getDataSize(responseData));
|
|
1286
1300
|
|
|
1287
1301
|
return { data: responseData };
|
|
@@ -1657,9 +1671,12 @@ class Collection {
|
|
|
1657
1671
|
}
|
|
1658
1672
|
}
|
|
1659
1673
|
|
|
1660
|
-
async insert(documents) {
|
|
1674
|
+
async insert(documents, options = {}) {
|
|
1675
|
+
Validator.validateOptions(options);
|
|
1676
|
+
|
|
1661
1677
|
return this.adapter.request('POST', `/collections/${encodeURIComponent(this.collectionName)}`, {
|
|
1662
|
-
documents
|
|
1678
|
+
documents,
|
|
1679
|
+
options
|
|
1663
1680
|
});
|
|
1664
1681
|
}
|
|
1665
1682
|
|