forked from trent_larson/crowd-funder-for-time-pwa
feat: fix raw results to really show the raw DB results
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user