dataply 0.0.22 → 0.0.23-alpha.1
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/dist/cjs/index.js +113 -15
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -2182,17 +2182,24 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2182
2182
|
}
|
|
2183
2183
|
return void 0;
|
|
2184
2184
|
}
|
|
2185
|
-
*keysStream(condition,
|
|
2186
|
-
const
|
|
2185
|
+
*keysStream(condition, options) {
|
|
2186
|
+
const { filterValues, limit, order = "asc" } = options ?? {};
|
|
2187
|
+
const stream = this.whereStream(condition, options);
|
|
2187
2188
|
const intersection = filterValues && filterValues.size > 0 ? filterValues : null;
|
|
2189
|
+
let count = 0;
|
|
2188
2190
|
for (const [key] of stream) {
|
|
2189
2191
|
if (intersection && !intersection.has(key)) {
|
|
2190
2192
|
continue;
|
|
2191
2193
|
}
|
|
2192
2194
|
yield key;
|
|
2195
|
+
count++;
|
|
2196
|
+
if (limit !== void 0 && count >= limit) {
|
|
2197
|
+
break;
|
|
2198
|
+
}
|
|
2193
2199
|
}
|
|
2194
2200
|
}
|
|
2195
|
-
*whereStream(condition,
|
|
2201
|
+
*whereStream(condition, options) {
|
|
2202
|
+
const { filterValues, limit, order = "asc" } = options ?? {};
|
|
2196
2203
|
const driverKey = this.getDriverKey(condition);
|
|
2197
2204
|
if (!driverKey) return;
|
|
2198
2205
|
const value = condition[driverKey];
|
|
@@ -2215,8 +2222,12 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2215
2222
|
earlyTerminate
|
|
2216
2223
|
);
|
|
2217
2224
|
let count = 0;
|
|
2225
|
+
const intersection = filterValues && filterValues.size > 0 ? filterValues : null;
|
|
2218
2226
|
for (const pair of generator) {
|
|
2219
2227
|
const [k, v] = pair;
|
|
2228
|
+
if (intersection && !intersection.has(k)) {
|
|
2229
|
+
continue;
|
|
2230
|
+
}
|
|
2220
2231
|
let isMatch = true;
|
|
2221
2232
|
for (const key in condition) {
|
|
2222
2233
|
if (key === driverKey) continue;
|
|
@@ -2236,16 +2247,16 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2236
2247
|
}
|
|
2237
2248
|
}
|
|
2238
2249
|
}
|
|
2239
|
-
keys(condition,
|
|
2250
|
+
keys(condition, options) {
|
|
2240
2251
|
const set = /* @__PURE__ */ new Set();
|
|
2241
|
-
for (const key of this.keysStream(condition,
|
|
2252
|
+
for (const key of this.keysStream(condition, options)) {
|
|
2242
2253
|
set.add(key);
|
|
2243
2254
|
}
|
|
2244
2255
|
return set;
|
|
2245
2256
|
}
|
|
2246
|
-
where(condition,
|
|
2257
|
+
where(condition, options) {
|
|
2247
2258
|
const map = /* @__PURE__ */ new Map();
|
|
2248
|
-
for (const [key, value] of this.whereStream(condition,
|
|
2259
|
+
for (const [key, value] of this.whereStream(condition, options)) {
|
|
2249
2260
|
map.set(key, value);
|
|
2250
2261
|
}
|
|
2251
2262
|
return map;
|
|
@@ -2273,6 +2284,33 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2273
2284
|
this._insertInParent(before, after.values[0], after);
|
|
2274
2285
|
}
|
|
2275
2286
|
}
|
|
2287
|
+
batchInsert(entries) {
|
|
2288
|
+
if (entries.length === 0) return;
|
|
2289
|
+
const sorted = [...entries].sort((a, b) => this.comparator.asc(a[1], b[1]));
|
|
2290
|
+
for (const [key, value] of sorted) {
|
|
2291
|
+
let before = this.insertableNode(value);
|
|
2292
|
+
before = this._insertAtLeaf(before, key, value);
|
|
2293
|
+
if (before.values.length === this.order) {
|
|
2294
|
+
let after = this._createNode(
|
|
2295
|
+
true,
|
|
2296
|
+
[],
|
|
2297
|
+
[],
|
|
2298
|
+
before.parent,
|
|
2299
|
+
null,
|
|
2300
|
+
null
|
|
2301
|
+
);
|
|
2302
|
+
const mid = Math.ceil(this.order / 2) - 1;
|
|
2303
|
+
after = this._cloneNode(after);
|
|
2304
|
+
after.values = before.values.slice(mid + 1);
|
|
2305
|
+
after.keys = before.keys.slice(mid + 1);
|
|
2306
|
+
before.values = before.values.slice(0, mid + 1);
|
|
2307
|
+
before.keys = before.keys.slice(0, mid + 1);
|
|
2308
|
+
this._updateNode(before);
|
|
2309
|
+
this._updateNode(after);
|
|
2310
|
+
this._insertInParent(before, after.values[0], after);
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2276
2314
|
_deleteEntry(node, key) {
|
|
2277
2315
|
if (!node.leaf) {
|
|
2278
2316
|
let keyIndex = -1;
|
|
@@ -2624,6 +2662,14 @@ var BPTreeSync = class extends BPTreeSyncTransaction {
|
|
|
2624
2662
|
throw new Error(`Transaction failed: ${result.error || "Commit failed due to conflict"}`);
|
|
2625
2663
|
}
|
|
2626
2664
|
}
|
|
2665
|
+
batchInsert(entries) {
|
|
2666
|
+
const tx = this.createTransaction();
|
|
2667
|
+
tx.batchInsert(entries);
|
|
2668
|
+
const result = tx.commit();
|
|
2669
|
+
if (!result.success) {
|
|
2670
|
+
throw new Error(`Transaction failed: ${result.error || "Commit failed due to conflict"}`);
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2627
2673
|
};
|
|
2628
2674
|
var Ryoiki2 = class _Ryoiki2 {
|
|
2629
2675
|
readings;
|
|
@@ -3249,17 +3295,24 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3249
3295
|
}
|
|
3250
3296
|
return void 0;
|
|
3251
3297
|
}
|
|
3252
|
-
async *keysStream(condition,
|
|
3253
|
-
const
|
|
3298
|
+
async *keysStream(condition, options) {
|
|
3299
|
+
const { filterValues, limit, order = "asc" } = options ?? {};
|
|
3300
|
+
const stream = this.whereStream(condition, options);
|
|
3254
3301
|
const intersection = filterValues && filterValues.size > 0 ? filterValues : null;
|
|
3302
|
+
let count = 0;
|
|
3255
3303
|
for await (const [key] of stream) {
|
|
3256
3304
|
if (intersection && !intersection.has(key)) {
|
|
3257
3305
|
continue;
|
|
3258
3306
|
}
|
|
3259
3307
|
yield key;
|
|
3308
|
+
count++;
|
|
3309
|
+
if (limit !== void 0 && count >= limit) {
|
|
3310
|
+
break;
|
|
3311
|
+
}
|
|
3260
3312
|
}
|
|
3261
3313
|
}
|
|
3262
|
-
async *whereStream(condition,
|
|
3314
|
+
async *whereStream(condition, options) {
|
|
3315
|
+
const { filterValues, limit, order = "asc" } = options ?? {};
|
|
3263
3316
|
const driverKey = this.getDriverKey(condition);
|
|
3264
3317
|
if (!driverKey) return;
|
|
3265
3318
|
const value = condition[driverKey];
|
|
@@ -3282,8 +3335,12 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3282
3335
|
earlyTerminate
|
|
3283
3336
|
);
|
|
3284
3337
|
let count = 0;
|
|
3338
|
+
const intersection = filterValues && filterValues.size > 0 ? filterValues : null;
|
|
3285
3339
|
for await (const pair of generator) {
|
|
3286
3340
|
const [k, v] = pair;
|
|
3341
|
+
if (intersection && !intersection.has(k)) {
|
|
3342
|
+
continue;
|
|
3343
|
+
}
|
|
3287
3344
|
let isMatch = true;
|
|
3288
3345
|
for (const key in condition) {
|
|
3289
3346
|
if (key === driverKey) continue;
|
|
@@ -3303,16 +3360,16 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3303
3360
|
}
|
|
3304
3361
|
}
|
|
3305
3362
|
}
|
|
3306
|
-
async keys(condition,
|
|
3363
|
+
async keys(condition, options) {
|
|
3307
3364
|
const set = /* @__PURE__ */ new Set();
|
|
3308
|
-
for await (const key of this.keysStream(condition,
|
|
3365
|
+
for await (const key of this.keysStream(condition, options)) {
|
|
3309
3366
|
set.add(key);
|
|
3310
3367
|
}
|
|
3311
3368
|
return set;
|
|
3312
3369
|
}
|
|
3313
|
-
async where(condition,
|
|
3370
|
+
async where(condition, options) {
|
|
3314
3371
|
const map = /* @__PURE__ */ new Map();
|
|
3315
|
-
for await (const [key, value] of this.whereStream(condition,
|
|
3372
|
+
for await (const [key, value] of this.whereStream(condition, options)) {
|
|
3316
3373
|
map.set(key, value);
|
|
3317
3374
|
}
|
|
3318
3375
|
return map;
|
|
@@ -3342,6 +3399,35 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3342
3399
|
}
|
|
3343
3400
|
});
|
|
3344
3401
|
}
|
|
3402
|
+
async batchInsert(entries) {
|
|
3403
|
+
if (entries.length === 0) return;
|
|
3404
|
+
return this.writeLock(0, async () => {
|
|
3405
|
+
const sorted = [...entries].sort((a, b) => this.comparator.asc(a[1], b[1]));
|
|
3406
|
+
for (const [key, value] of sorted) {
|
|
3407
|
+
let before = await this.insertableNode(value);
|
|
3408
|
+
before = await this._insertAtLeaf(before, key, value);
|
|
3409
|
+
if (before.values.length === this.order) {
|
|
3410
|
+
let after = await this._createNode(
|
|
3411
|
+
true,
|
|
3412
|
+
[],
|
|
3413
|
+
[],
|
|
3414
|
+
before.parent,
|
|
3415
|
+
null,
|
|
3416
|
+
null
|
|
3417
|
+
);
|
|
3418
|
+
const mid = Math.ceil(this.order / 2) - 1;
|
|
3419
|
+
after = this._cloneNode(after);
|
|
3420
|
+
after.values = before.values.slice(mid + 1);
|
|
3421
|
+
after.keys = before.keys.slice(mid + 1);
|
|
3422
|
+
before.values = before.values.slice(0, mid + 1);
|
|
3423
|
+
before.keys = before.keys.slice(0, mid + 1);
|
|
3424
|
+
await this._updateNode(before);
|
|
3425
|
+
await this._updateNode(after);
|
|
3426
|
+
await this._insertInParent(before, after.values[0], after);
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
3429
|
+
});
|
|
3430
|
+
}
|
|
3345
3431
|
async _deleteEntry(node, key) {
|
|
3346
3432
|
if (!node.leaf) {
|
|
3347
3433
|
let keyIndex = -1;
|
|
@@ -3699,6 +3785,16 @@ var BPTreeAsync = class extends BPTreeAsyncTransaction {
|
|
|
3699
3785
|
}
|
|
3700
3786
|
});
|
|
3701
3787
|
}
|
|
3788
|
+
async batchInsert(entries) {
|
|
3789
|
+
return this.writeLock(1, async () => {
|
|
3790
|
+
const tx = await this.createTransaction();
|
|
3791
|
+
await tx.batchInsert(entries);
|
|
3792
|
+
const result = await tx.commit();
|
|
3793
|
+
if (!result.success) {
|
|
3794
|
+
throw new Error(`Transaction failed: ${result.error || "Commit failed due to conflict"}`);
|
|
3795
|
+
}
|
|
3796
|
+
});
|
|
3797
|
+
}
|
|
3702
3798
|
};
|
|
3703
3799
|
var SerializeStrategy = class {
|
|
3704
3800
|
order;
|
|
@@ -8711,6 +8807,7 @@ var RowTableEngine = class {
|
|
|
8711
8807
|
if (!this.factory.isDataPage(lastInsertDataPage)) {
|
|
8712
8808
|
throw new Error(`Last insert page is not data page`);
|
|
8713
8809
|
}
|
|
8810
|
+
const batchInsertData = [];
|
|
8714
8811
|
for (const data of dataList) {
|
|
8715
8812
|
const pk = ++lastPk;
|
|
8716
8813
|
const willRowSize = this.getRequiredRowSize(data);
|
|
@@ -8755,9 +8852,10 @@ var RowTableEngine = class {
|
|
|
8755
8852
|
await this.pfs.setPage(lastInsertDataPageId, lastInsertDataPage, tx);
|
|
8756
8853
|
}
|
|
8757
8854
|
}
|
|
8758
|
-
|
|
8855
|
+
batchInsertData.push([this.getRID(), pk]);
|
|
8759
8856
|
pks.push(pk);
|
|
8760
8857
|
}
|
|
8858
|
+
await btx.batchInsert(batchInsertData);
|
|
8761
8859
|
tx.__markBPTreeDirty();
|
|
8762
8860
|
const freshMetadataPage = await this.pfs.getMetadata(tx);
|
|
8763
8861
|
this.metadataPageManager.setLastInsertPageId(freshMetadataPage, lastInsertDataPageId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataply",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23-alpha.1",
|
|
4
4
|
"description": "A lightweight storage engine for Node.js with support for MVCC, WAL.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "izure <admin@izure.org>",
|
|
@@ -49,6 +49,6 @@
|
|
|
49
49
|
"hookall": "^2.2.0",
|
|
50
50
|
"mvcc-api": "^1.3.4",
|
|
51
51
|
"ryoiki": "^1.2.0",
|
|
52
|
-
"serializable-bptree": "^8.
|
|
52
|
+
"serializable-bptree": "^8.3.0"
|
|
53
53
|
}
|
|
54
54
|
}
|