| 197 | * a process-global would race. |
| 198 | */ |
| 199 | export function createDatabase(dbPath: string, opts?: { readOnly?: boolean }): { db: SqliteDatabase; backend: SqliteBackend } { |
| 200 | try { |
| 201 | return { db: new NodeSqliteAdapter(dbPath, opts), backend: 'node-sqlite' }; |
| 202 | } catch (error) { |
| 203 | // node:sqlite loaded and SQLite itself failed — not a missing-module case. |
| 204 | const shared = toWslSharedIndexError(error, dbPath); |
| 205 | if (shared) throw shared; |
| 206 | const msg = error instanceof Error ? error.message : String(error); |
| 207 | throw new Error( |
| 208 | 'Failed to open SQLite via the built-in node:sqlite module.\n' + |
| 209 | 'CodeGraph requires node:sqlite (Node.js 22.5+). Install the self-contained\n' + |
| 210 | 'CodeGraph release (it bundles a compatible Node), or run on Node 22.5+.\n' + |
| 211 | `Underlying error: ${msg}` |
| 212 | ); |
| 213 | } |
| 214 | } |