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>;
|
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
|
// Database utility methods
|
||||||
/**
|
/**
|
||||||
* Generates an INSERT SQL statement for a given model and table.
|
* Generates an INSERT SQL statement for a given model and table.
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import {
|
|||||||
import { logger } from "../../utils/logger";
|
import { logger } from "../../utils/logger";
|
||||||
|
|
||||||
interface QueuedOperation {
|
interface QueuedOperation {
|
||||||
type: "run" | "query";
|
type: "run" | "query" | "rawQuery";
|
||||||
sql: string;
|
sql: string;
|
||||||
params: unknown[];
|
params: unknown[];
|
||||||
resolve: (value: unknown) => void;
|
resolve: (value: unknown) => void;
|
||||||
@@ -159,6 +159,14 @@ export class CapacitorPlatformService implements PlatformService {
|
|||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "rawQuery": {
|
||||||
|
const queryResult = await this.db.query(
|
||||||
|
operation.sql,
|
||||||
|
operation.params,
|
||||||
|
);
|
||||||
|
result = queryResult;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
operation.resolve(result);
|
operation.resolve(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1270,6 +1278,14 @@ export class CapacitorPlatformService implements PlatformService {
|
|||||||
return undefined;
|
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.
|
* Checks if running on Capacitor platform.
|
||||||
* @returns true, as this is the Capacitor implementation
|
* @returns true, as this is the Capacitor implementation
|
||||||
|
|||||||
@@ -636,6 +636,17 @@ export class WebPlatformService implements PlatformService {
|
|||||||
} as GetOneRowRequest);
|
} 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.
|
* Rotates the camera between front and back cameras.
|
||||||
* @returns Promise that resolves when the camera is rotated
|
* @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
|
* Utility method for retrieving master settings
|
||||||
* Common pattern used across many components
|
* Common pattern used across many components
|
||||||
@@ -1870,6 +1891,7 @@ export interface IPlatformServiceMixin {
|
|||||||
sql: string,
|
sql: string,
|
||||||
params?: unknown[],
|
params?: unknown[],
|
||||||
): Promise<SqlValue[] | undefined>;
|
): Promise<SqlValue[] | undefined>;
|
||||||
|
$dbRawQuery(sql: string, params?: unknown[]): Promise<unknown | undefined>;
|
||||||
$getMasterSettings(fallback?: Settings | null): Promise<Settings | null>;
|
$getMasterSettings(fallback?: Settings | null): Promise<Settings | null>;
|
||||||
$getMergedSettings(
|
$getMergedSettings(
|
||||||
defaultKey: string,
|
defaultKey: string,
|
||||||
@@ -1994,6 +2016,7 @@ declare module "@vue/runtime-core" {
|
|||||||
sql: string,
|
sql: string,
|
||||||
params?: unknown[],
|
params?: unknown[],
|
||||||
): Promise<unknown[] | undefined>;
|
): Promise<unknown[] | undefined>;
|
||||||
|
$dbRawQuery(sql: string, params?: unknown[]): Promise<unknown | undefined>;
|
||||||
$getMasterSettings(defaults?: Settings | null): Promise<Settings | null>;
|
$getMasterSettings(defaults?: Settings | null): Promise<Settings | null>;
|
||||||
$getMergedSettings(
|
$getMergedSettings(
|
||||||
key: string,
|
key: string,
|
||||||
|
|||||||
@@ -78,7 +78,7 @@
|
|||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="rounded border-gray-300"
|
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>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="sqlResult" class="mt-4">
|
<div v-if="sqlResult" class="mt-4">
|
||||||
@@ -975,13 +975,13 @@ export default class Help extends Vue {
|
|||||||
async executeSql() {
|
async executeSql() {
|
||||||
try {
|
try {
|
||||||
const isSelect = this.sqlQuery.trim().toLowerCase().startsWith("select");
|
const isSelect = this.sqlQuery.trim().toLowerCase().startsWith("select");
|
||||||
|
|
||||||
if (this.returnRawResults) {
|
if (this.returnRawResults) {
|
||||||
// Use direct platform service methods for raw, unparsed results
|
// Use direct platform service methods for raw, unparsed results
|
||||||
if (isSelect) {
|
if (isSelect) {
|
||||||
this.sqlResult = await this.$dbQuery(this.sqlQuery);
|
this.sqlResult = await this.$dbRawQuery(this.sqlQuery);
|
||||||
} else {
|
} else {
|
||||||
this.sqlResult = await this.$dbExec(this.sqlQuery);
|
this.sqlResult = await this.$exec(this.sqlQuery);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Use methods that normalize the result objects
|
// Use methods that normalize the result objects
|
||||||
@@ -991,7 +991,7 @@ export default class Help extends Vue {
|
|||||||
this.sqlResult = await this.$exec(this.sqlQuery);
|
this.sqlResult = await this.$exec(this.sqlQuery);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.log("Test SQL Result:", this.sqlResult);
|
logger.log("Test SQL Result:", this.sqlResult);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Test SQL Error:", error);
|
logger.error("Test SQL Error:", error);
|
||||||
|
|||||||
Reference in New Issue
Block a user