diff --git a/src/services/AbsurdSqlDatabaseService.ts b/src/services/AbsurdSqlDatabaseService.ts index 6d7dd9c9..ee2f00e3 100644 --- a/src/services/AbsurdSqlDatabaseService.ts +++ b/src/services/AbsurdSqlDatabaseService.ts @@ -107,16 +107,9 @@ class AbsurdSqlDatabaseService implements DatabaseService { const extractMigrationNames: (result: QueryExecResult[]) => Set = ( 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 = 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 diff --git a/src/services/platforms/CapacitorPlatformService.ts b/src/services/platforms/CapacitorPlatformService.ts index 320c8cc8..2fc08599 100644 --- a/src/services/platforms/CapacitorPlatformService.ts +++ b/src/services/platforms/CapacitorPlatformService.ts @@ -236,6 +236,10 @@ export class CapacitorPlatformService implements PlatformService { throw new Error("Database not initialized"); } + const sqlExec: (sql: string) => Promise = + this.db.execute.bind(this.db); + const sqlQuery: (sql: string) => Promise = + this.db.query.bind(this.db); const extractMigrationNames: (result: DBSQLiteValues) => Set = ( 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 = - this.db.execute.bind(this.db); - const sqlQuery: (sql: string) => Promise = - this.db.query.bind(this.db); runMigrations(sqlExec, sqlQuery, extractMigrationNames); }