From 297fe3cec6eb1d8b582059c8282a5785b463bfc3 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Tue, 16 Sep 2025 21:08:22 -0600 Subject: [PATCH] feat: fix raw results to really show the raw DB results --- src/services/PlatformService.ts | 10 ++++++++ .../platforms/CapacitorPlatformService.ts | 18 ++++++++++++++- src/services/platforms/WebPlatformService.ts | 11 +++++++++ src/utils/PlatformServiceMixin.ts | 23 +++++++++++++++++++ src/views/TestView.vue | 10 ++++---- 5 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/services/PlatformService.ts b/src/services/PlatformService.ts index c20e2796..a8ae9ee7 100644 --- a/src/services/PlatformService.ts +++ b/src/services/PlatformService.ts @@ -155,6 +155,16 @@ export interface PlatformService { */ dbGetOneRow(sql: string, params?: unknown[]): Promise; + /** + * Not recommended except for debugging. + * Return the raw result of a SQL query. + * + * @param sql - The SQL query to execute + * @param params - The parameters to pass to the query + * @returns Promise resolving to the raw query result, or undefined if no results + */ + dbRawQuery(sql: string, params?: unknown[]): Promise; + // Database utility methods /** * Generates an INSERT SQL statement for a given model and table. diff --git a/src/services/platforms/CapacitorPlatformService.ts b/src/services/platforms/CapacitorPlatformService.ts index 746f422a..a487690c 100644 --- a/src/services/platforms/CapacitorPlatformService.ts +++ b/src/services/platforms/CapacitorPlatformService.ts @@ -24,7 +24,7 @@ import { import { logger } from "../../utils/logger"; interface QueuedOperation { - type: "run" | "query"; + type: "run" | "query" | "rawQuery"; sql: string; params: unknown[]; resolve: (value: unknown) => void; @@ -159,6 +159,14 @@ export class CapacitorPlatformService implements PlatformService { }; break; } + case "rawQuery": { + const queryResult = await this.db.query( + operation.sql, + operation.params, + ); + result = queryResult; + break; + } } operation.resolve(result); } catch (error) { @@ -1270,6 +1278,14 @@ export class CapacitorPlatformService implements PlatformService { return undefined; } + /** + * @see PlatformService.dbRawQuery + */ + async dbRawQuery(sql: string, params?: unknown[]): Promise { + await this.waitForInitialization(); + return this.queueOperation("rawQuery", sql, params || []); + } + /** * Checks if running on Capacitor platform. * @returns true, as this is the Capacitor implementation diff --git a/src/services/platforms/WebPlatformService.ts b/src/services/platforms/WebPlatformService.ts index dda411d3..3d8248f5 100644 --- a/src/services/platforms/WebPlatformService.ts +++ b/src/services/platforms/WebPlatformService.ts @@ -636,6 +636,17 @@ export class WebPlatformService implements PlatformService { } as GetOneRowRequest); } + /** + * @see PlatformService.dbRawQuery + */ + async dbRawQuery( + sql: string, + params?: unknown[], + ): Promise { + // This class doesn't post-process the result, so we can just use it. + return this.dbQuery(sql, params); + } + /** * Rotates the camera between front and back cameras. * @returns Promise that resolves when the camera is rotated diff --git a/src/utils/PlatformServiceMixin.ts b/src/utils/PlatformServiceMixin.ts index 254a8396..7fe727be 100644 --- a/src/utils/PlatformServiceMixin.ts +++ b/src/utils/PlatformServiceMixin.ts @@ -489,6 +489,27 @@ export const PlatformServiceMixin = { } }, + /** + * Database raw query method with error handling + */ + async $dbRawQuery(sql: string, params?: unknown[]) { + try { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return await (this as any).platformService.dbRawQuery(sql, params); + } catch (error) { + logger.error( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + `[${(this as any).$options.name}] Database raw query failed:`, + { + sql, + params, + error, + }, + ); + throw error; + } + }, + /** * Utility method for retrieving master settings * Common pattern used across many components @@ -1870,6 +1891,7 @@ export interface IPlatformServiceMixin { sql: string, params?: unknown[], ): Promise; + $dbRawQuery(sql: string, params?: unknown[]): Promise; $getMasterSettings(fallback?: Settings | null): Promise; $getMergedSettings( defaultKey: string, @@ -1994,6 +2016,7 @@ declare module "@vue/runtime-core" { sql: string, params?: unknown[], ): Promise; + $dbRawQuery(sql: string, params?: unknown[]): Promise; $getMasterSettings(defaults?: Settings | null): Promise; $getMergedSettings( key: string, diff --git a/src/views/TestView.vue b/src/views/TestView.vue index 1e19a68f..5a339f8c 100644 --- a/src/views/TestView.vue +++ b/src/views/TestView.vue @@ -78,7 +78,7 @@ type="checkbox" class="rounded border-gray-300" /> - Return Raw Results + Return Raw Results (only raw for queries)
@@ -975,13 +975,13 @@ export default class Help extends Vue { async executeSql() { try { const isSelect = this.sqlQuery.trim().toLowerCase().startsWith("select"); - + if (this.returnRawResults) { // Use direct platform service methods for raw, unparsed results if (isSelect) { - this.sqlResult = await this.$dbQuery(this.sqlQuery); + this.sqlResult = await this.$dbRawQuery(this.sqlQuery); } else { - this.sqlResult = await this.$dbExec(this.sqlQuery); + this.sqlResult = await this.$exec(this.sqlQuery); } } else { // Use methods that normalize the result objects @@ -991,7 +991,7 @@ export default class Help extends Vue { this.sqlResult = await this.$exec(this.sqlQuery); } } - + logger.log("Test SQL Result:", this.sqlResult); } catch (error) { logger.error("Test SQL Error:", error);