* Initialize a new database at the given path
(dbPath: string)
| 123 | * Initialize a new database at the given path |
| 124 | */ |
| 125 | static initialize(dbPath: string): DatabaseConnection { |
| 126 | // Ensure parent directory exists |
| 127 | const dir = path.dirname(dbPath); |
| 128 | if (!fs.existsSync(dir)) { |
| 129 | fs.mkdirSync(dir, { recursive: true }); |
| 130 | } |
| 131 | |
| 132 | const { db, backend } = createDatabase(dbPath); |
| 133 | return withOpenFailures(db, dbPath, () => DatabaseConnection.initializeOn(db, backend, dbPath)); |
| 134 | } |
| 135 | |
| 136 | /** The rest of {@link initialize}: configure the connection and create the schema. */ |
| 137 | private static initializeOn(db: SqliteDatabase, backend: SqliteBackend, dbPath: string): DatabaseConnection { |