@keyv/sqlite 4.0.8 → 6.0.0-alpha.2

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 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` and [`busyTimeout`](https://sqlite.org/c3ref/busy_timeout.html) option.
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
@@ -35,8 +35,8 @@ __export(index_exports, {
35
35
  default: () => index_default
36
36
  });
37
37
  module.exports = __toCommonJS(index_exports);
38
- var import_node_events = __toESM(require("events"), 1);
39
38
  var import_node_util = require("util");
39
+ var import_hookified = require("hookified");
40
40
  var import_keyv = __toESM(require("keyv"), 1);
41
41
  var import_sqlite3 = __toESM(require("sqlite3"), 1);
42
42
  var toTableString = (input) => {
@@ -46,15 +46,13 @@ var toTableString = (input) => {
46
46
  }
47
47
  return /^[a-zA-Z]/.test(sanitized) ? sanitized : `_${sanitized}`;
48
48
  };
49
- var KeyvSqlite = class extends import_node_events.default {
50
- ttlSupport;
49
+ var KeyvSqlite = class extends import_hookified.Hookified {
51
50
  opts;
52
51
  namespace;
53
52
  close;
54
53
  query;
55
54
  constructor(keyvOptions) {
56
- super();
57
- this.ttlSupport = false;
55
+ super({ throwOnEmptyListeners: 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
- // @ts-expect-error
84
- query: (0, import_node_util.promisify)(database.all).bind(database),
85
- // @ts-expect-error
86
- close: (0, import_node_util.promisify)(database.close).bind(database)
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,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import EventEmitter from 'node:events';
1
+ import { Hookified } from 'hookified';
2
2
  import Keyv, { KeyvStoreAdapter, StoredData } from 'keyv';
3
3
 
4
4
  type DbQuery = (sqlString: string, ...parameter: unknown[]) => Promise<any>;
@@ -11,14 +11,15 @@ 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;
17
19
  }>;
18
20
  };
19
21
 
20
- declare class KeyvSqlite extends EventEmitter implements KeyvStoreAdapter {
21
- ttlSupport: boolean;
22
+ declare class KeyvSqlite extends Hookified implements KeyvStoreAdapter {
22
23
  opts: KeyvSqliteOptions;
23
24
  namespace?: string;
24
25
  close: DbClose;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import EventEmitter from 'node:events';
1
+ import { Hookified } from 'hookified';
2
2
  import Keyv, { KeyvStoreAdapter, StoredData } from 'keyv';
3
3
 
4
4
  type DbQuery = (sqlString: string, ...parameter: unknown[]) => Promise<any>;
@@ -11,14 +11,15 @@ 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;
17
19
  }>;
18
20
  };
19
21
 
20
- declare class KeyvSqlite extends EventEmitter implements KeyvStoreAdapter {
21
- ttlSupport: boolean;
22
+ declare class KeyvSqlite extends Hookified implements KeyvStoreAdapter {
22
23
  opts: KeyvSqliteOptions;
23
24
  namespace?: string;
24
25
  close: DbClose;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/index.ts
2
- import EventEmitter from "events";
3
2
  import { promisify } from "util";
3
+ import { Hookified } from "hookified";
4
4
  import Keyv from "keyv";
5
5
  import sqlite3 from "sqlite3";
6
6
  var toTableString = (input) => {
@@ -10,15 +10,13 @@ var toTableString = (input) => {
10
10
  }
11
11
  return /^[a-zA-Z]/.test(sanitized) ? sanitized : `_${sanitized}`;
12
12
  };
13
- var KeyvSqlite = class extends EventEmitter {
14
- ttlSupport;
13
+ var KeyvSqlite = class extends Hookified {
15
14
  opts;
16
15
  namespace;
17
16
  close;
18
17
  query;
19
18
  constructor(keyvOptions) {
20
- super();
21
- this.ttlSupport = false;
19
+ super({ throwOnEmptyListeners: 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
- // @ts-expect-error
48
- query: promisify(database.all).bind(database),
49
- // @ts-expect-error
50
- close: promisify(database.close).bind(database)
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keyv/sqlite",
3
- "version": "4.0.8",
3
+ "version": "6.0.0-alpha.2",
4
4
  "description": "SQLite storage adapter for Keyv",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -41,10 +41,11 @@
41
41
  },
42
42
  "homepage": "https://github.com/jaredwray/keyv",
43
43
  "dependencies": {
44
+ "hookified": "^2.0.0",
44
45
  "sqlite3": "^5.1.7"
45
46
  },
46
47
  "peerDependencies": {
47
- "keyv": "^5.6.0"
48
+ "keyv": "^6.0.0-alpha.2"
48
49
  },
49
50
  "devDependencies": {
50
51
  "@biomejs/biome": "^2.3.11",
@@ -53,7 +54,7 @@
53
54
  "rimraf": "^6.1.2",
54
55
  "tsd": "^0.33.0",
55
56
  "vitest": "^4.0.17",
56
- "@keyv/test-suite": "^2.1.2"
57
+ "@keyv/test-suite": "^6.0.0-alpha.2"
57
58
  },
58
59
  "tsd": {
59
60
  "directory": "test"