* What `codegraph.db` holds, asked of SQLite itself through a read-only * connection: the codegraph schema, a database without it, not a database at * all (SQLITE_NOTADB), or `unknown` — locked, busy, a WAL db in a directory we * cannot create `-shm` in (read-only checkout, mount, another user's
(dbPath: string)
| 214 | * second connection opened and closed here leaves the first one's locks alone. |
| 215 | */ |
| 216 | function probeSchema(dbPath: string): 'schema' | 'no-schema' | 'not-sqlite' | 'unknown' { |
| 217 | // eslint-disable-next-line @typescript-eslint/no-require-imports |
| 218 | const { DatabaseSync } = require('node:sqlite'); |
| 219 | let db: any = null; |
| 220 | try { |
| 221 | db = new DatabaseSync(dbPath, { readOnly: true }); |
| 222 | const row = db.prepare("SELECT 1 AS ok FROM sqlite_master WHERE type = 'table' AND name = 'nodes'").get(); |
| 223 | return row !== undefined ? 'schema' : 'no-schema'; |
| 224 | } catch (error) { |
| 225 | return (error as { errcode?: number })?.errcode === SQLITE_NOTADB ? 'not-sqlite' : 'unknown'; |
| 226 | } finally { |
| 227 | // Never hold the handle: Windows file locking would block the owner. |
| 228 | try { db?.close(); } catch { /* already closed */ } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Find the nearest parent directory containing .codegraph/ |
no test coverage detected