deepbase-sqlite 3.8.6 → 3.9.0
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/README.md +16 -11
- package/package.json +2 -2
- package/src/SqliteDriver.js +5 -1
- package/src/index.d.ts +3 -2
- package/test/test-multiprocess.js +3 -3
- package/test/test.js +13 -0
package/README.md
CHANGED
|
@@ -28,10 +28,13 @@ Stores data in SQLite database files. Perfect for:
|
|
|
28
28
|
|
|
29
29
|
```javascript
|
|
30
30
|
import DeepBase from 'deepbase';
|
|
31
|
+
import { resolvePath } from 'deepbase/path';
|
|
31
32
|
import SqliteDriver from 'deepbase-sqlite';
|
|
32
33
|
|
|
34
|
+
const dataPath = resolvePath(import.meta.url, './data');
|
|
35
|
+
|
|
33
36
|
const db = new DeepBase(new SqliteDriver({
|
|
34
|
-
path:
|
|
37
|
+
path: dataPath,
|
|
35
38
|
name: 'mydb',
|
|
36
39
|
pragma: 'balanced' // default — omit for same result
|
|
37
40
|
}));
|
|
@@ -42,11 +45,15 @@ await db.set('users', 'alice', { name: 'Alice', age: 30 });
|
|
|
42
45
|
const alice = await db.get('users', 'alice');
|
|
43
46
|
```
|
|
44
47
|
|
|
48
|
+
`path` is required and must be absolute. `resolvePath()` anchors a relative
|
|
49
|
+
path to your application module instead of `process.cwd()` or the installed
|
|
50
|
+
package location.
|
|
51
|
+
|
|
45
52
|
## Options
|
|
46
53
|
|
|
47
54
|
```javascript
|
|
48
55
|
new SqliteDriver({
|
|
49
|
-
path: '
|
|
56
|
+
path: '/var/lib/myapp/data', // Required absolute directory for database files
|
|
50
57
|
name: 'default', // Database filename (without .db)
|
|
51
58
|
pragma: 'balanced', // Performance profile: 'none' | 'safe' | 'balanced' | 'fast'
|
|
52
59
|
busyTimeoutMs: 5000, // Native wait per lock attempt
|
|
@@ -75,8 +82,8 @@ Uses `better-sqlite3` for synchronous operations wrapped in async API:
|
|
|
75
82
|
Multiple instances and same-host processes may safely point to the same database file. Each driver owns its connection and lifecycle; SQLite coordinates writers using WAL, `BEGIN IMMEDIATE`, a busy timeout, and bounded transaction retries:
|
|
76
83
|
|
|
77
84
|
```javascript
|
|
78
|
-
const db1 = new DeepBase(new SqliteDriver({ name: 'mydb' }));
|
|
79
|
-
const db2 = new DeepBase(new SqliteDriver({ name: 'mydb' }));
|
|
85
|
+
const db1 = new DeepBase(new SqliteDriver({ path: '/var/lib/myapp/data', name: 'mydb' }));
|
|
86
|
+
const db2 = new DeepBase(new SqliteDriver({ path: '/var/lib/myapp/data', name: 'mydb' }));
|
|
80
87
|
// Independent connections; disconnecting db1 does not close db2.
|
|
81
88
|
```
|
|
82
89
|
|
|
@@ -160,16 +167,16 @@ All WAL modes use `journal_mode=WAL` and `temp_store=MEMORY`. Lock waiting is co
|
|
|
160
167
|
|
|
161
168
|
```javascript
|
|
162
169
|
// Backward-compatible (no PRAGMAs, no WITHOUT ROWID)
|
|
163
|
-
new SqliteDriver({ name: 'mydb', pragma: 'none' })
|
|
170
|
+
new SqliteDriver({ path: '/var/lib/myapp/data', name: 'mydb', pragma: 'none' })
|
|
164
171
|
|
|
165
172
|
// Maximum durability
|
|
166
|
-
new SqliteDriver({ name: 'mydb', pragma: 'safe' })
|
|
173
|
+
new SqliteDriver({ path: '/var/lib/myapp/data', name: 'mydb', pragma: 'safe' })
|
|
167
174
|
|
|
168
175
|
// Recommended (default)
|
|
169
|
-
new SqliteDriver({ name: 'mydb', pragma: 'balanced' })
|
|
176
|
+
new SqliteDriver({ path: '/var/lib/myapp/data', name: 'mydb', pragma: 'balanced' })
|
|
170
177
|
|
|
171
178
|
// Maximum throughput
|
|
172
|
-
new SqliteDriver({ name: 'mydb', pragma: 'fast' })
|
|
179
|
+
new SqliteDriver({ path: '/var/lib/myapp/data', name: 'mydb', pragma: 'fast' })
|
|
173
180
|
```
|
|
174
181
|
|
|
175
182
|
`SqliteFastDriver` is kept as a named alias for backward compatibility:
|
|
@@ -237,7 +244,7 @@ import SqliteDriver from 'deepbase-sqlite';
|
|
|
237
244
|
import MongoDriver from 'deepbase-mongodb';
|
|
238
245
|
|
|
239
246
|
const db = new DeepBase([
|
|
240
|
-
new SqliteDriver({ path: '
|
|
247
|
+
new SqliteDriver({ path: '/var/lib/myapp/data' }),
|
|
241
248
|
new MongoDriver({ url: 'mongodb://localhost:27017' })
|
|
242
249
|
]);
|
|
243
250
|
|
|
@@ -379,5 +386,3 @@ Notes:
|
|
|
379
386
|
## License
|
|
380
387
|
|
|
381
388
|
MIT - Copyright (c) Martin Clasen
|
|
382
|
-
|
|
383
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepbase-sqlite",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
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.
|
|
20
|
+
"deepbase": "^3.9.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"mocha": "^10.8.2"
|
package/src/SqliteDriver.js
CHANGED
|
@@ -11,9 +11,13 @@ export class SqliteDriver extends DeepBaseDriver {
|
|
|
11
11
|
constructor({ name, path, pragma, busyTimeoutMs, busyRetry, ...opts } = {}) {
|
|
12
12
|
super(opts);
|
|
13
13
|
|
|
14
|
+
if (typeof path !== 'string' || path.trim() === '' || !pathModule.isAbsolute(path)) {
|
|
15
|
+
throw new TypeError('SqliteDriver requires an absolute "path" option.');
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
const config = resolveSqliteConfig({ pragma, busyTimeoutMs, busyRetry });
|
|
15
19
|
this.name = name || 'default';
|
|
16
|
-
this.path = path
|
|
20
|
+
this.path = path;
|
|
17
21
|
this.pragma = config.pragma;
|
|
18
22
|
this.pragmaConfig = config.pragmaConfig;
|
|
19
23
|
this.busyTimeoutMs = config.busyTimeoutMs;
|
package/src/index.d.ts
CHANGED
|
@@ -19,14 +19,15 @@ export interface SqliteCheckpointResult {
|
|
|
19
19
|
|
|
20
20
|
export interface SqliteDriverOptions extends DeepBaseDriverOptions {
|
|
21
21
|
name?: string;
|
|
22
|
-
|
|
22
|
+
/** Required absolute storage directory. */
|
|
23
|
+
path: string;
|
|
23
24
|
pragma?: 'none' | 'safe' | 'balanced' | 'fast';
|
|
24
25
|
busyTimeoutMs?: number;
|
|
25
26
|
busyRetry?: SqliteBusyRetryOptions;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export class SqliteDriver extends DeepBaseDriver {
|
|
29
|
-
constructor(options
|
|
30
|
+
constructor(options: SqliteDriverOptions);
|
|
30
31
|
|
|
31
32
|
name: string;
|
|
32
33
|
path: string;
|
|
@@ -68,15 +68,15 @@ describe('SqliteDriver multi-process safety', function () {
|
|
|
68
68
|
|
|
69
69
|
it('validates concurrency options eagerly', function () {
|
|
70
70
|
assert.throws(
|
|
71
|
-
() => new SqliteDriver({ pragma: 'invalid' }),
|
|
71
|
+
() => new SqliteDriver({ path: testDataPath, pragma: 'invalid' }),
|
|
72
72
|
/pragma must be one of/,
|
|
73
73
|
);
|
|
74
74
|
assert.throws(
|
|
75
|
-
() => new SqliteDriver({ busyTimeoutMs: -1 }),
|
|
75
|
+
() => new SqliteDriver({ path: testDataPath, busyTimeoutMs: -1 }),
|
|
76
76
|
/busyTimeoutMs must be a non-negative integer/,
|
|
77
77
|
);
|
|
78
78
|
assert.throws(
|
|
79
|
-
() => new SqliteDriver({ busyRetry: { maxAttempts: 0 } }),
|
|
79
|
+
() => new SqliteDriver({ path: testDataPath, busyRetry: { maxAttempts: 0 } }),
|
|
80
80
|
/maxAttempts must be at least 1/,
|
|
81
81
|
);
|
|
82
82
|
});
|
package/test/test.js
CHANGED
|
@@ -11,6 +11,19 @@ const testDataPath = path.join(__dirname, 'test-data');
|
|
|
11
11
|
|
|
12
12
|
const PRAGMA_MODES = ['none', 'safe', 'balanced', 'fast'];
|
|
13
13
|
|
|
14
|
+
describe('SqliteDriver configuration', function () {
|
|
15
|
+
it('should require an absolute storage path', function () {
|
|
16
|
+
assert.throws(
|
|
17
|
+
() => new SqliteDriver({ name: 'missing-path' }),
|
|
18
|
+
/requires an absolute "path" option/,
|
|
19
|
+
);
|
|
20
|
+
assert.throws(
|
|
21
|
+
() => new SqliteDriver({ name: 'relative-path', path: './data' }),
|
|
22
|
+
/requires an absolute "path" option/,
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
14
27
|
for (const pragma of PRAGMA_MODES) {
|
|
15
28
|
describe(`SqliteDriver [pragma=${pragma}]`, function () {
|
|
16
29
|
let db;
|