* Open a session DB (read-only by default, cached).
(sessionId: string, options?: { readonly?: boolean })
| 73 | * Open a session DB (read-only by default, cached). |
| 74 | */ |
| 75 | open(sessionId: string, options?: { readonly?: boolean }): DatabaseAdapter | null { |
| 76 | this.assertCompatible() |
| 77 | |
| 78 | if (this.cache.has(sessionId)) { |
| 79 | return this.cache.get(sessionId)! |
| 80 | } |
| 81 | |
| 82 | const dbPath = this.getDbPath(sessionId) |
| 83 | if (!fs.existsSync(dbPath)) return null |
| 84 | |
| 85 | this.migrateIfNeeded(dbPath) |
| 86 | this.assertCompatible() |
| 87 | |
| 88 | const adapter = openBetterSqliteDatabase(dbPath, { |
| 89 | readonly: options?.readonly ?? true, |
| 90 | nativeBinding: this.nativeBinding, |
| 91 | }) |
| 92 | this.cache.set(sessionId, adapter) |
| 93 | return adapter |
| 94 | } |
| 95 | |
| 96 | private migrateIfNeeded(dbPath: string): void { |
| 97 | const readonlyAdapter = openBetterSqliteDatabase(dbPath, { |
no test coverage detected