* Open an existing database
(dbPath: string)
| 96 | * Open an existing database |
| 97 | */ |
| 98 | static open(dbPath: string): DatabaseConnection { |
| 99 | if (!fs.existsSync(dbPath)) { |
| 100 | throw new Error(`Database not found: ${dbPath}`); |
| 101 | } |
| 102 | |
| 103 | const { db, backend } = createDatabase(dbPath); |
| 104 | |
| 105 | configureConnection(db); |
| 106 | |
| 107 | // Check and run migrations if needed |
| 108 | const conn = new DatabaseConnection(db, dbPath, backend); |
| 109 | const currentVersion = getCurrentVersion(db); |
| 110 | |
| 111 | if (currentVersion < CURRENT_SCHEMA_VERSION) { |
| 112 | runMigrations(db, currentVersion); |
| 113 | } |
| 114 | |
| 115 | return conn; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Get the underlying database instance |
no test coverage detected