@keyv/sqlite 4.0.6 → 6.0.0-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/README.md +13 -3
- package/dist/index.cjs +23 -9
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +23 -9
- package/package.json +19 -13
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ const keyv = new Keyv(new KeyvSqlite('sqlite://path/to/database.sqlite'));
|
|
|
25
25
|
keyv.on('error', handleConnectionError);
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
You can specify the `table
|
|
28
|
+
You can specify the `table`, [`busyTimeout`](https://sqlite.org/c3ref/busy_timeout.html), and `wal` options.
|
|
29
29
|
|
|
30
30
|
e.g:
|
|
31
31
|
|
|
@@ -35,12 +35,22 @@ import KeyvSqlite from '@keyv/sqlite';
|
|
|
35
35
|
|
|
36
36
|
const keyvSqlite = new KeyvSqlite('sqlite://path/to/database.sqlite', {
|
|
37
37
|
table: 'cache',
|
|
38
|
-
busyTimeout: 10000
|
|
38
|
+
busyTimeout: 10000,
|
|
39
|
+
wal: true // Enable WAL mode for better concurrency
|
|
39
40
|
});
|
|
40
41
|
|
|
41
|
-
const keyv = new Keyv({ store: keyvSqlite });
|
|
42
|
+
const keyv = new Keyv({ store: keyvSqlite });
|
|
42
43
|
```
|
|
43
44
|
|
|
45
|
+
### Options
|
|
46
|
+
|
|
47
|
+
- `uri` - The SQLite database URI (default: `'sqlite://:memory:'`)
|
|
48
|
+
- `table` - The table name to use for storage (default: `'keyv'`)
|
|
49
|
+
- `busyTimeout` - Sets a busy handler that sleeps for a specified amount of time when a table is locked
|
|
50
|
+
- `wal` - Enable [Write-Ahead Logging](https://sqlite.org/wal.html) mode for better concurrency and performance (default: `false`)
|
|
51
|
+
- **Note:** WAL mode is not supported for in-memory databases (`:memory:`). A warning will be logged and the option will be ignored.
|
|
52
|
+
- `keySize` - The maximum key size in bytes (default: `255`, max: `65535`)
|
|
53
|
+
|
|
44
54
|
You can also use a helper function to create `Keyv` with `KeyvSqlite` store.
|
|
45
55
|
|
|
46
56
|
```js
|
package/dist/index.cjs
CHANGED
|
@@ -47,14 +47,12 @@ var toTableString = (input) => {
|
|
|
47
47
|
return /^[a-zA-Z]/.test(sanitized) ? sanitized : `_${sanitized}`;
|
|
48
48
|
};
|
|
49
49
|
var KeyvSqlite = class extends import_node_events.default {
|
|
50
|
-
ttlSupport;
|
|
51
50
|
opts;
|
|
52
51
|
namespace;
|
|
53
52
|
close;
|
|
54
53
|
query;
|
|
55
54
|
constructor(keyvOptions) {
|
|
56
55
|
super();
|
|
57
|
-
this.ttlSupport = false;
|
|
58
56
|
let options = {
|
|
59
57
|
dialect: "sqlite",
|
|
60
58
|
uri: "sqlite://:memory:"
|
|
@@ -79,12 +77,24 @@ var KeyvSqlite = class extends import_node_events.default {
|
|
|
79
77
|
resolve(database);
|
|
80
78
|
}
|
|
81
79
|
});
|
|
82
|
-
}).then((database) =>
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
}).then(async (database) => {
|
|
81
|
+
const query = (0, import_node_util.promisify)(database.all).bind(database);
|
|
82
|
+
const close = (0, import_node_util.promisify)(database.close).bind(database);
|
|
83
|
+
if (options.wal) {
|
|
84
|
+
const isInMemory = options.db === ":memory:" || options.db === "";
|
|
85
|
+
if (isInMemory) {
|
|
86
|
+
console.warn(
|
|
87
|
+
"@keyv/sqlite: WAL mode is not supported for in-memory databases. The wal option will be ignored."
|
|
88
|
+
);
|
|
89
|
+
} else {
|
|
90
|
+
await query("PRAGMA journal_mode=WAL");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
query,
|
|
95
|
+
close
|
|
96
|
+
};
|
|
97
|
+
});
|
|
88
98
|
this.opts = {
|
|
89
99
|
table: "keyv",
|
|
90
100
|
keySize: 255,
|
|
@@ -100,7 +110,10 @@ var KeyvSqlite = class extends import_node_events.default {
|
|
|
100
110
|
const createTable = `CREATE TABLE IF NOT EXISTS ${this.opts.table}(key VARCHAR(${keySize}) PRIMARY KEY, value TEXT )`;
|
|
101
111
|
const connected = this.opts.connect().then(
|
|
102
112
|
async (database) => database.query(createTable).then(() => database)
|
|
103
|
-
).catch((error) =>
|
|
113
|
+
).catch((error) => {
|
|
114
|
+
this.emit("error", error);
|
|
115
|
+
throw error;
|
|
116
|
+
});
|
|
104
117
|
this.query = async (sqlString, ...parameter) => connected.then(
|
|
105
118
|
async (database) => database.query(sqlString, ...parameter)
|
|
106
119
|
);
|
|
@@ -195,3 +208,4 @@ var index_default = KeyvSqlite;
|
|
|
195
208
|
KeyvSqlite,
|
|
196
209
|
createKeyv
|
|
197
210
|
});
|
|
211
|
+
/* v8 ignore next -- @preserve */
|
package/dist/index.d.cts
CHANGED
|
@@ -11,6 +11,8 @@ type KeyvSqliteOptions = {
|
|
|
11
11
|
keySize?: number;
|
|
12
12
|
db?: string;
|
|
13
13
|
iterationLimit?: number | string;
|
|
14
|
+
/** Enable WAL (Write-Ahead Logging) mode. */
|
|
15
|
+
wal?: boolean;
|
|
14
16
|
connect?: () => Promise<{
|
|
15
17
|
query: DbQuery;
|
|
16
18
|
close: DbClose;
|
|
@@ -18,7 +20,6 @@ type KeyvSqliteOptions = {
|
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
declare class KeyvSqlite extends EventEmitter implements KeyvStoreAdapter {
|
|
21
|
-
ttlSupport: boolean;
|
|
22
23
|
opts: KeyvSqliteOptions;
|
|
23
24
|
namespace?: string;
|
|
24
25
|
close: DbClose;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ type KeyvSqliteOptions = {
|
|
|
11
11
|
keySize?: number;
|
|
12
12
|
db?: string;
|
|
13
13
|
iterationLimit?: number | string;
|
|
14
|
+
/** Enable WAL (Write-Ahead Logging) mode. */
|
|
15
|
+
wal?: boolean;
|
|
14
16
|
connect?: () => Promise<{
|
|
15
17
|
query: DbQuery;
|
|
16
18
|
close: DbClose;
|
|
@@ -18,7 +20,6 @@ type KeyvSqliteOptions = {
|
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
declare class KeyvSqlite extends EventEmitter implements KeyvStoreAdapter {
|
|
21
|
-
ttlSupport: boolean;
|
|
22
23
|
opts: KeyvSqliteOptions;
|
|
23
24
|
namespace?: string;
|
|
24
25
|
close: DbClose;
|
package/dist/index.js
CHANGED
|
@@ -11,14 +11,12 @@ var toTableString = (input) => {
|
|
|
11
11
|
return /^[a-zA-Z]/.test(sanitized) ? sanitized : `_${sanitized}`;
|
|
12
12
|
};
|
|
13
13
|
var KeyvSqlite = class extends EventEmitter {
|
|
14
|
-
ttlSupport;
|
|
15
14
|
opts;
|
|
16
15
|
namespace;
|
|
17
16
|
close;
|
|
18
17
|
query;
|
|
19
18
|
constructor(keyvOptions) {
|
|
20
19
|
super();
|
|
21
|
-
this.ttlSupport = false;
|
|
22
20
|
let options = {
|
|
23
21
|
dialect: "sqlite",
|
|
24
22
|
uri: "sqlite://:memory:"
|
|
@@ -43,12 +41,24 @@ var KeyvSqlite = class extends EventEmitter {
|
|
|
43
41
|
resolve(database);
|
|
44
42
|
}
|
|
45
43
|
});
|
|
46
|
-
}).then((database) =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
}).then(async (database) => {
|
|
45
|
+
const query = promisify(database.all).bind(database);
|
|
46
|
+
const close = promisify(database.close).bind(database);
|
|
47
|
+
if (options.wal) {
|
|
48
|
+
const isInMemory = options.db === ":memory:" || options.db === "";
|
|
49
|
+
if (isInMemory) {
|
|
50
|
+
console.warn(
|
|
51
|
+
"@keyv/sqlite: WAL mode is not supported for in-memory databases. The wal option will be ignored."
|
|
52
|
+
);
|
|
53
|
+
} else {
|
|
54
|
+
await query("PRAGMA journal_mode=WAL");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
query,
|
|
59
|
+
close
|
|
60
|
+
};
|
|
61
|
+
});
|
|
52
62
|
this.opts = {
|
|
53
63
|
table: "keyv",
|
|
54
64
|
keySize: 255,
|
|
@@ -64,7 +74,10 @@ var KeyvSqlite = class extends EventEmitter {
|
|
|
64
74
|
const createTable = `CREATE TABLE IF NOT EXISTS ${this.opts.table}(key VARCHAR(${keySize}) PRIMARY KEY, value TEXT )`;
|
|
65
75
|
const connected = this.opts.connect().then(
|
|
66
76
|
async (database) => database.query(createTable).then(() => database)
|
|
67
|
-
).catch((error) =>
|
|
77
|
+
).catch((error) => {
|
|
78
|
+
this.emit("error", error);
|
|
79
|
+
throw error;
|
|
80
|
+
});
|
|
68
81
|
this.query = async (sqlString, ...parameter) => connected.then(
|
|
69
82
|
async (database) => database.query(sqlString, ...parameter)
|
|
70
83
|
);
|
|
@@ -159,3 +172,4 @@ export {
|
|
|
159
172
|
createKeyv,
|
|
160
173
|
index_default as default
|
|
161
174
|
};
|
|
175
|
+
/* v8 ignore next -- @preserve */
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keyv/sqlite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-alpha.1",
|
|
4
4
|
"description": "SQLite storage adapter for Keyv",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.
|
|
7
|
-
"module": "dist/index.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"require":
|
|
12
|
-
|
|
11
|
+
"require": {
|
|
12
|
+
"types": "./dist/index.d.cts",
|
|
13
|
+
"default": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
13
19
|
}
|
|
14
20
|
},
|
|
15
21
|
"repository": {
|
|
@@ -38,16 +44,16 @@
|
|
|
38
44
|
"sqlite3": "^5.1.7"
|
|
39
45
|
},
|
|
40
46
|
"peerDependencies": {
|
|
41
|
-
"keyv": "^
|
|
47
|
+
"keyv": "^6.0.0-alpha.1"
|
|
42
48
|
},
|
|
43
49
|
"devDependencies": {
|
|
44
|
-
"@biomejs/biome": "^2.
|
|
45
|
-
"@faker-js/faker": "^10.
|
|
46
|
-
"@vitest/coverage-v8": "^
|
|
47
|
-
"rimraf": "^6.
|
|
50
|
+
"@biomejs/biome": "^2.3.11",
|
|
51
|
+
"@faker-js/faker": "^10.2.0",
|
|
52
|
+
"@vitest/coverage-v8": "^4.0.17",
|
|
53
|
+
"rimraf": "^6.1.2",
|
|
48
54
|
"tsd": "^0.33.0",
|
|
49
|
-
"vitest": "^
|
|
50
|
-
"@keyv/test-suite": "^
|
|
55
|
+
"vitest": "^4.0.17",
|
|
56
|
+
"@keyv/test-suite": "^6.0.0-alpha.1"
|
|
51
57
|
},
|
|
52
58
|
"tsd": {
|
|
53
59
|
"directory": "test"
|