Browse Source

feat: fix raw results to really show the raw DB results

pull/188/head
Trent Larson 2 days ago
parent
commit
297fe3cec6
  1. 10
      src/services/PlatformService.ts
  2. 18
      src/services/platforms/CapacitorPlatformService.ts
  3. 11
      src/services/platforms/WebPlatformService.ts
  4. 23
      src/utils/PlatformServiceMixin.ts
  5. 10
      src/views/TestView.vue

10
src/services/PlatformService.ts

@ -155,6 +155,16 @@ export interface PlatformService {
*/
dbGetOneRow(sql: string, params?: unknown[]): Promise<unknown[] | undefined>;
/**
* 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<unknown | undefined>;
// Database utility methods
/**
* Generates an INSERT SQL statement for a given model and table.

18
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<unknown> {
await this.waitForInitialization();
return this.queueOperation("rawQuery", sql, params || []);
}
/**
* Checks if running on Capacitor platform.
* @returns true, as this is the Capacitor implementation

11
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<unknown | undefined> {
// 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

23
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<SqlValue[] | undefined>;
$dbRawQuery(sql: string, params?: unknown[]): Promise<unknown | undefined>;
$getMasterSettings(fallback?: Settings | null): Promise<Settings | null>;
$getMergedSettings(
defaultKey: string,
@ -1994,6 +2016,7 @@ declare module "@vue/runtime-core" {
sql: string,
params?: unknown[],
): Promise<unknown[] | undefined>;
$dbRawQuery(sql: string, params?: unknown[]): Promise<unknown | undefined>;
$getMasterSettings(defaults?: Settings | null): Promise<Settings | null>;
$getMergedSettings(
key: string,

10
src/views/TestView.vue

@ -78,7 +78,7 @@
type="checkbox"
class="rounded border-gray-300"
/>
<span class="text-sm">Return Raw Results</span>
<span class="text-sm">Return Raw Results (only raw for queries)</span>
</label>
</div>
<div v-if="sqlResult" class="mt-4">
@ -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);

Loading…
Cancel
Save