(filePath: string)
| 6 | const connections = new Map<string, Database.Database>(); |
| 7 | |
| 8 | export function openDatabase(filePath: string): Database.Database { |
| 9 | if (connections.has(filePath)) { |
| 10 | return connections.get(filePath)!; |
| 11 | } |
| 12 | const dir = path.dirname(filePath); |
| 13 | fs.mkdirSync(dir, { recursive: true }); |
| 14 | const db = new Database(filePath); |
| 15 | db.pragma('journal_mode = WAL'); |
| 16 | db.pragma('foreign_keys = ON'); |
| 17 | db.pragma('synchronous = NORMAL'); |
| 18 | db.pragma('busy_timeout = 5000'); |
| 19 | connections.set(filePath, db); |
| 20 | return db; |
| 21 | } |
| 22 | |
| 23 | export function closeAll(): void { |
| 24 | for (const db of connections.values()) { |
no test coverage detected