resplite 1.3.5 → 1.3.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resplite",
3
- "version": "1.3.5",
3
+ "version": "1.3.6",
4
4
  "description": "A RESP2 server with practical Redis compatibility, backed by SQLite",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -1,20 +1,27 @@
1
1
  /**
2
2
  * Open SQLite database, apply pragmas and schema.
3
+ * If the path points to a file in a directory that does not exist, the directory is created.
3
4
  */
4
5
 
5
6
  import Database from 'better-sqlite3';
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
6
9
  import { applyPragmas } from './pragmas.js';
7
10
  import { applySchema } from './schema.js';
8
11
  import { applyMigrationSchema } from './migration-schema.js';
9
12
 
10
13
  /**
11
- * @param {string} path - Database file path
14
+ * @param {string} dbPath - Database file path (or ':memory:')
12
15
  * @param {object} [options] - Options: pragmaTemplate (default|performance|safety|minimal), plus any better-sqlite3 options
13
16
  * @returns {import('better-sqlite3').Database}
14
17
  */
15
- export function openDb(path, options = {}) {
18
+ export function openDb(dbPath, options = {}) {
19
+ if (dbPath !== ':memory:') {
20
+ const dir = path.dirname(dbPath);
21
+ if (dir) fs.mkdirSync(dir, { recursive: true });
22
+ }
16
23
  const { pragmaTemplate = 'default', ...dbOptions } = options;
17
- const db = new Database(path, dbOptions);
24
+ const db = new Database(dbPath, dbOptions);
18
25
  applyPragmas(db, pragmaTemplate);
19
26
  applySchema(db);
20
27
  applyMigrationSchema(db);