refactor for clarity (no logic changes)

This commit is contained in:
2025-06-05 18:30:25 -06:00
parent 493438215c
commit 4256cbcb61
2 changed files with 6 additions and 13 deletions

View File

@@ -107,16 +107,9 @@ class AbsurdSqlDatabaseService implements DatabaseService {
const extractMigrationNames: (result: QueryExecResult[]) => Set<string> = (
result,
) => {
const queryResult = result as QueryExecResult[];
// Even with the "select name" query, the QueryExecResult may be [] (which doesn't make sense to me).
if (queryResult.length > 0) {
const singleResult = queryResult[0];
const executedMigrations: Set<string> = new Set(
singleResult.values.map((row) => row[0] as string),
);
return executedMigrations;
}
return new Set();
const names = result?.[0]?.values.map((row) => row[0] as string) || [];
return new Set(names);
};
// Run migrations

View File

@@ -236,6 +236,10 @@ export class CapacitorPlatformService implements PlatformService {
throw new Error("Database not initialized");
}
const sqlExec: (sql: string) => Promise<capSQLiteChanges> =
this.db.execute.bind(this.db);
const sqlQuery: (sql: string) => Promise<DBSQLiteValues> =
this.db.query.bind(this.db);
const extractMigrationNames: (result: DBSQLiteValues) => Set<string> = (
result,
) => {
@@ -243,10 +247,6 @@ export class CapacitorPlatformService implements PlatformService {
result.values?.map((row: { name: string }) => row.name) || [];
return new Set(names);
};
const sqlExec: (sql: string) => Promise<capSQLiteChanges> =
this.db.execute.bind(this.db);
const sqlQuery: (sql: string) => Promise<DBSQLiteValues> =
this.db.query.bind(this.db);
runMigrations(sqlExec, sqlQuery, extractMigrationNames);
}