deepbase-sqlite 3.6.8 → 3.6.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/package.json +2 -2
- package/src/SqliteDriver.js +7 -2
- package/test/test.js +26 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepbase-sqlite",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.9",
|
|
4
4
|
"description": "⚡ DeepBase SQLite - SQLite database driver",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.cjs",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"better-sqlite3": "^11.8.1"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"deepbase": "^3.6.
|
|
20
|
+
"deepbase": "^3.6.9"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"test": "mocha test/test.js"
|
package/src/SqliteDriver.js
CHANGED
|
@@ -125,7 +125,7 @@ export class SqliteDriver extends DeepBaseDriver {
|
|
|
125
125
|
|
|
126
126
|
this._setTxn = this.db.transaction((key, jsonValue, keys) => {
|
|
127
127
|
this._expandParentObjects(keys);
|
|
128
|
-
this.
|
|
128
|
+
this._replaceRow(key, jsonValue);
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
this._delTxn = this.db.transaction((key, likePattern, keys) => {
|
|
@@ -139,7 +139,7 @@ export class SqliteDriver extends DeepBaseDriver {
|
|
|
139
139
|
const newValue = func(currentValue);
|
|
140
140
|
const key = this._pathToKey(keys);
|
|
141
141
|
this._expandParentObjects(keys);
|
|
142
|
-
this.
|
|
142
|
+
this._replaceRow(key, JSON.stringify(newValue));
|
|
143
143
|
return keys;
|
|
144
144
|
});
|
|
145
145
|
|
|
@@ -220,6 +220,11 @@ export class SqliteDriver extends DeepBaseDriver {
|
|
|
220
220
|
return keys;
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
+
_replaceRow(key, jsonValue) {
|
|
224
|
+
this.delChildrenStmt.run(this._likePrefix(key));
|
|
225
|
+
this.setStmt.run(key, jsonValue, this._consumeSeq());
|
|
226
|
+
}
|
|
227
|
+
|
|
223
228
|
async del(...keys) {
|
|
224
229
|
if (keys.length === 0) {
|
|
225
230
|
this.db.exec('DELETE FROM deepbase');
|
package/test/test.js
CHANGED
|
@@ -429,6 +429,32 @@ for (const pragma of PRAGMA_MODES) {
|
|
|
429
429
|
assert.deepStrictEqual(await db.get('settings'), { a: 1, b: 99, c: 3, d: 4 });
|
|
430
430
|
});
|
|
431
431
|
|
|
432
|
+
it('should replace stale child keys when setting a parent object', async function () {
|
|
433
|
+
await db.set('profile', 'chinchon:MZM3Z', 'remoteData', 'denounces', 1000);
|
|
434
|
+
await db.set('profile', 'chinchon:MZM3Z', {
|
|
435
|
+
game: 'chinchon',
|
|
436
|
+
remoteData: {
|
|
437
|
+
hid: 'MZM3Z',
|
|
438
|
+
denounces: 0,
|
|
439
|
+
},
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
const profile = await db.get('profile', 'chinchon:MZM3Z');
|
|
443
|
+
assert.strictEqual(profile.remoteData.denounces, 0);
|
|
444
|
+
assert.strictEqual(await db.get('profile', 'chinchon:MZM3Z', 'remoteData', 'denounces'), 0);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('should keep sibling keys with similar prefixes when replacing a parent object', async function () {
|
|
448
|
+
await db.set('a', 'b', 'c', 1);
|
|
449
|
+
await db.set('a', 'bc', 'c', 2);
|
|
450
|
+
await db.set('a', 'b', { c: 0 });
|
|
451
|
+
|
|
452
|
+
assert.deepStrictEqual(await db.get('a'), {
|
|
453
|
+
b: { c: 0 },
|
|
454
|
+
bc: { c: 2 },
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
|
|
432
458
|
it('should handle nested object then deeper nesting', async function () {
|
|
433
459
|
await db.set('user', { name: 'Alice', meta: { role: 'admin' } });
|
|
434
460
|
await db.set('user', 'meta', 'role', 'user');
|