fix platform services to use correct settings table schema

- Fix WebPlatformService settings methods to use id/accountDid columns
- Fix CapacitorPlatformService settings methods to use id/accountDid columns
- Replace WHERE key = 'default' with WHERE id = 1 for default settings
- Replace WHERE key = ? with WHERE accountDid = ? for user settings
- Update insertDidSpecificSettings to use accountDid column
- Update retrieveSettingsForActiveAccount to select all columns and convert to object
- Resolves "no such column: key" SQL errors after util.ts migration
- Ensures compatibility with new settings table structure

All platform services now use correct database schema for settings operations.
This commit is contained in:
Matthew Raymer
2025-07-16 09:43:09 +00:00
parent 8825c52ebc
commit 9cbb9bf3c6
6 changed files with 184 additions and 36 deletions

View File

@@ -1323,16 +1323,13 @@ export class CapacitorPlatformService implements PlatformService {
): Promise<void> {
const keys = Object.keys(settings);
const setClause = keys.map((key) => `${key} = ?`).join(", ");
const sql = `UPDATE settings SET ${setClause} WHERE key = 'default'`;
const sql = `UPDATE settings SET ${setClause} WHERE id = 1`;
const params = keys.map((key) => settings[key]);
await this.dbExec(sql, params);
}
async insertDidSpecificSettings(did: string): Promise<void> {
await this.dbExec("INSERT INTO settings (key, value) VALUES (?, ?)", [
did,
"{}",
]);
await this.dbExec("INSERT INTO settings (accountDid) VALUES (?)", [did]);
}
async updateDidSpecificSettings(
@@ -1341,7 +1338,7 @@ export class CapacitorPlatformService implements PlatformService {
): Promise<void> {
const keys = Object.keys(settings);
const setClause = keys.map((key) => `${key} = ?`).join(", ");
const sql = `UPDATE settings SET ${setClause} WHERE key = ?`;
const sql = `UPDATE settings SET ${setClause} WHERE accountDid = ?`;
const params = [...keys.map((key) => settings[key]), did];
await this.dbExec(sql, params);
}
@@ -1350,15 +1347,21 @@ export class CapacitorPlatformService implements PlatformService {
string,
unknown
> | null> {
const result = await this.dbQuery(
"SELECT value FROM settings WHERE key = 'default'",
);
if (result?.values?.[0]?.[0]) {
try {
return JSON.parse(result.values[0][0] as string);
} catch {
return null;
}
const result = await this.dbQuery("SELECT * FROM settings WHERE id = 1");
if (result?.values?.[0]) {
// Convert the row to an object
const row = result.values[0];
const columns = result.columns || [];
const settings: Record<string, unknown> = {};
columns.forEach((column, index) => {
if (column !== "id") {
// Exclude the id column
settings[column] = row[index];
}
});
return settings;
}
return null;
}