deepbase-sqlite 3.6.9 → 3.6.10
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 +14 -2
- package/test/test.js +31 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepbase-sqlite",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.10",
|
|
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.10"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"test": "mocha test/test.js"
|
package/src/SqliteDriver.js
CHANGED
|
@@ -352,12 +352,24 @@ export class SqliteDriver extends DeepBaseDriver {
|
|
|
352
352
|
if (path.length === 0) return;
|
|
353
353
|
|
|
354
354
|
if (path.length === 1) {
|
|
355
|
-
|
|
355
|
+
const key = path[0];
|
|
356
|
+
const existing = obj[key];
|
|
357
|
+
if (
|
|
358
|
+
value === null &&
|
|
359
|
+
existing !== null &&
|
|
360
|
+
typeof existing === 'object' &&
|
|
361
|
+
!Array.isArray(existing) &&
|
|
362
|
+
Object.keys(existing).length > 0
|
|
363
|
+
) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
obj[key] = value;
|
|
356
367
|
return;
|
|
357
368
|
}
|
|
358
369
|
|
|
359
370
|
const key = path[0];
|
|
360
|
-
|
|
371
|
+
const current = obj[key];
|
|
372
|
+
if (!obj.hasOwnProperty(key) || current === null || typeof current !== 'object' || Array.isArray(current)) {
|
|
361
373
|
obj[key] = {};
|
|
362
374
|
}
|
|
363
375
|
|
package/test/test.js
CHANGED
|
@@ -394,6 +394,37 @@ for (const pragma of PRAGMA_MODES) {
|
|
|
394
394
|
assert.deepStrictEqual(await db.get(), { new: 'data' });
|
|
395
395
|
assert.strictEqual(await db.get('old'), null);
|
|
396
396
|
});
|
|
397
|
+
|
|
398
|
+
it('should read root when a null parent row coexists with child rows', async function () {
|
|
399
|
+
const itemPath = await db.add('user1', 'message', 'pending', { test: 1 });
|
|
400
|
+
const itemId = itemPath[itemPath.length - 1];
|
|
401
|
+
const driver = db.getDriver(0);
|
|
402
|
+
driver.db.prepare('INSERT OR REPLACE INTO deepbase (key, value, seq) VALUES (?, ?, ?)').run(
|
|
403
|
+
'user1.message.pending',
|
|
404
|
+
'null',
|
|
405
|
+
999,
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
const pending = {
|
|
409
|
+
[itemId]: { test: 1 },
|
|
410
|
+
};
|
|
411
|
+
const message = {
|
|
412
|
+
pending,
|
|
413
|
+
};
|
|
414
|
+
const user = {
|
|
415
|
+
message,
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
assert.deepStrictEqual(await db.get(), {
|
|
419
|
+
user1: {
|
|
420
|
+
message,
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
assert.deepStrictEqual(await db.get('user1'), user);
|
|
424
|
+
assert.deepStrictEqual(await db.get('user1', 'message'), message);
|
|
425
|
+
assert.deepStrictEqual(await db.get('user1', 'message', 'pending'), pending);
|
|
426
|
+
assert.deepStrictEqual(await db.keys('user1', 'message', 'pending'), [itemId]);
|
|
427
|
+
});
|
|
397
428
|
});
|
|
398
429
|
|
|
399
430
|
describe('Deep Nesting', function () {
|