feat(database): add index.ts with factory function

This commit is contained in:
2026-06-22 05:37:39 +00:00
parent f9bcbb1f9c
commit abe92e58a0
+26
View File
@@ -0,0 +1,26 @@
import { SqliteAdapter } from './SqliteAdapter';
import { migrationManager } from './migrations';
export async function createDatabase(dbPath: string): Promise<SqliteAdapter> {
const db = new SqliteAdapter(dbPath);
// Apply migrations
const currentVersion = await db.getMigrationVersion();
const targetVersion = migrationManager.getLatestVersion();
if (currentVersion < targetVersion) {
// Apply all migrations from currentVersion + 1 to targetVersion
for (let version = currentVersion + 1; version <= targetVersion; version++) {
const migration = migrationManager.getMigrationByVersion(version);
if (migration) {
await db.runMigration(migration.up);
await db.setMigrationVersion(version);
}
}
}
return db;
}
export * from './DatabaseInterface';
export * from './SqliteAdapter';