dataply 0.0.23-alpha.0 → 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 +77 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -2284,6 +2284,33 @@ var BPTreeSyncTransaction = class extends BPTreeTransaction {
|
|
|
2284
2284
|
this._insertInParent(before, after.values[0], after);
|
|
2285
2285
|
}
|
|
2286
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
|
+
}
|
|
2287
2314
|
_deleteEntry(node, key) {
|
|
2288
2315
|
if (!node.leaf) {
|
|
2289
2316
|
let keyIndex = -1;
|
|
@@ -2635,6 +2662,14 @@ var BPTreeSync = class extends BPTreeSyncTransaction {
|
|
|
2635
2662
|
throw new Error(`Transaction failed: ${result.error || "Commit failed due to conflict"}`);
|
|
2636
2663
|
}
|
|
2637
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
|
+
}
|
|
2638
2673
|
};
|
|
2639
2674
|
var Ryoiki2 = class _Ryoiki2 {
|
|
2640
2675
|
readings;
|
|
@@ -3364,6 +3399,35 @@ var BPTreeAsyncTransaction = class extends BPTreeTransaction {
|
|
|
3364
3399
|
}
|
|
3365
3400
|
});
|
|
3366
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
|
+
}
|
|
3367
3431
|
async _deleteEntry(node, key) {
|
|
3368
3432
|
if (!node.leaf) {
|
|
3369
3433
|
let keyIndex = -1;
|
|
@@ -3721,6 +3785,16 @@ var BPTreeAsync = class extends BPTreeAsyncTransaction {
|
|
|
3721
3785
|
}
|
|
3722
3786
|
});
|
|
3723
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
|
+
}
|
|
3724
3798
|
};
|
|
3725
3799
|
var SerializeStrategy = class {
|
|
3726
3800
|
order;
|
|
@@ -8733,6 +8807,7 @@ var RowTableEngine = class {
|
|
|
8733
8807
|
if (!this.factory.isDataPage(lastInsertDataPage)) {
|
|
8734
8808
|
throw new Error(`Last insert page is not data page`);
|
|
8735
8809
|
}
|
|
8810
|
+
const batchInsertData = [];
|
|
8736
8811
|
for (const data of dataList) {
|
|
8737
8812
|
const pk = ++lastPk;
|
|
8738
8813
|
const willRowSize = this.getRequiredRowSize(data);
|
|
@@ -8777,9 +8852,10 @@ var RowTableEngine = class {
|
|
|
8777
8852
|
await this.pfs.setPage(lastInsertDataPageId, lastInsertDataPage, tx);
|
|
8778
8853
|
}
|
|
8779
8854
|
}
|
|
8780
|
-
|
|
8855
|
+
batchInsertData.push([this.getRID(), pk]);
|
|
8781
8856
|
pks.push(pk);
|
|
8782
8857
|
}
|
|
8858
|
+
await btx.batchInsert(batchInsertData);
|
|
8783
8859
|
tx.__markBPTreeDirty();
|
|
8784
8860
|
const freshMetadataPage = await this.pfs.getMetadata(tx);
|
|
8785
8861
|
this.metadataPageManager.setLastInsertPageId(freshMetadataPage, lastInsertDataPageId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataply",
|
|
3
|
-
"version": "0.0.23-alpha.
|
|
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
|
}
|