Browse Source

adjust so DB calls go to the factory

pull/137/head
Trent Larson 2 weeks ago
parent
commit
3a6f585de0
  1. 4
      src/libs/util.ts
  2. 18
      src/services/PlatformService.ts
  3. 8
      src/services/platforms/CapacitorPlatformService.ts
  4. 8
      src/services/platforms/ElectronPlatformService.ts
  5. 8
      src/services/platforms/PyWebViewPlatformService.ts
  6. 16
      src/services/platforms/WebPlatformService.ts
  7. 8
      src/views/AccountViewView.vue
  8. 2
      src/views/HelpOnboardingView.vue
  9. 2
      src/views/HelpView.vue
  10. 31
      src/views/TestView.vue

4
src/libs/util.ts

@ -29,6 +29,7 @@ import { KeyMeta } from "../libs/crypto/vc";
import { createPeerDid } from "../libs/crypto/vc/didPeer";
import { registerCredential } from "../libs/crypto/vc/passkeyDidPeer";
import { logger } from "../utils/logger";
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
export interface GiverReceiverInputInfo {
did?: string;
@ -552,7 +553,8 @@ export const generateSaveAndActivateIdentity = async (): Promise<string> => {
});
// add to the new sql db
await databaseService.run(
const platformService = PlatformServiceFactory.getInstance();
await platformService.dbExec(
`INSERT INTO accounts (dateCreated, derivationPath, did, identity, mnemonic, publicKeyHex)
VALUES (?, ?, ?, ?, ?, ?)`,
[

18
src/services/PlatformService.ts

@ -1,3 +1,5 @@
import { QueryExecResult } from "@/interfaces/database";
/**
* Represents the result of an image capture or selection operation.
* Contains both the image data as a Blob and the associated filename.
@ -98,4 +100,20 @@ export interface PlatformService {
* @returns Promise that resolves when the deep link has been handled
*/
handleDeepLink(url: string): Promise<void>;
/**
* Executes a SQL query on the database.
* @param sql - The SQL query to execute
* @param params - The parameters to pass to the query
* @returns Promise resolving to the query result
*/
dbQuery(sql: string, params?: unknown[]): Promise<QueryExecResult>;
/**
* Executes a create/update/delete on the database.
* @param sql - The SQL statement to execute
* @param params - The parameters to pass to the statement
* @returns Promise resolving to the result of the statement
*/
dbExec(sql: string, params?: unknown[]): Promise<{ changes: number; lastId?: number }>;
}

8
src/services/platforms/CapacitorPlatformService.ts

@ -7,6 +7,7 @@ import { Filesystem, Directory, Encoding } from "@capacitor/filesystem";
import { Camera, CameraResultType, CameraSource } from "@capacitor/camera";
import { Share } from "@capacitor/share";
import { logger } from "../../utils/logger";
import { QueryExecResult } from "@/interfaces/database";
/**
* Platform service implementation for Capacitor (mobile) platform.
@ -476,4 +477,11 @@ export class CapacitorPlatformService implements PlatformService {
// This is just a placeholder for the interface
return Promise.resolve();
}
dbQuery(sql: string, params?: unknown[]): Promise<QueryExecResult> {
throw new Error("Not implemented for " + sql + " with params " + params);
}
dbExec(sql: string, params?: unknown[]): Promise<{ changes: number; lastId?: number }> {
throw new Error("Not implemented for " + sql + " with params " + params);
}
}

8
src/services/platforms/ElectronPlatformService.ts

@ -4,6 +4,7 @@ import {
PlatformCapabilities,
} from "../PlatformService";
import { logger } from "../../utils/logger";
import { QueryExecResult } from "@/interfaces/database";
/**
* Platform service implementation for Electron (desktop) platform.
@ -108,4 +109,11 @@ export class ElectronPlatformService implements PlatformService {
logger.error("handleDeepLink not implemented in Electron platform");
throw new Error("Not implemented");
}
dbQuery(sql: string, params?: unknown[]): Promise<QueryExecResult> {
throw new Error("Not implemented for " + sql + " with params " + params);
}
dbExec(sql: string, params?: unknown[]): Promise<{ changes: number; lastId?: number }> {
throw new Error("Not implemented for " + sql + " with params " + params);
}
}

8
src/services/platforms/PyWebViewPlatformService.ts

@ -4,6 +4,7 @@ import {
PlatformCapabilities,
} from "../PlatformService";
import { logger } from "../../utils/logger";
import { QueryExecResult } from "@/interfaces/database";
/**
* Platform service implementation for PyWebView platform.
@ -109,4 +110,11 @@ export class PyWebViewPlatformService implements PlatformService {
logger.error("handleDeepLink not implemented in PyWebView platform");
throw new Error("Not implemented");
}
dbQuery(sql: string, params?: unknown[]): Promise<QueryExecResult> {
throw new Error("Not implemented for " + sql + " with params " + params);
}
dbExec(sql: string, params?: unknown[]): Promise<{ changes: number; lastId?: number }> {
throw new Error("Not implemented for " + sql + " with params " + params);
}
}

16
src/services/platforms/WebPlatformService.ts

@ -4,6 +4,8 @@ import {
PlatformCapabilities,
} from "../PlatformService";
import { logger } from "../../utils/logger";
import { QueryExecResult } from "@/interfaces/database";
import databaseService from "../database";
/**
* Platform service implementation for web browser platform.
@ -359,4 +361,18 @@ export class WebPlatformService implements PlatformService {
async writeAndShareFile(_fileName: string, _content: string): Promise<void> {
throw new Error("File system access not available in web platform");
}
/**
* @see PlatformService.dbQuery
*/
dbQuery(sql: string, params?: unknown[]): Promise<QueryExecResult> {
return databaseService.query(sql, params).then((result) => result[0]);
}
/**
* @see PlatformService.dbExec
*/
dbExec(sql: string, params?: unknown[]): Promise<{ changes: number; lastId?: number }> {
return databaseService.run(sql, params);
}
}

8
src/views/AccountViewView.vue

@ -955,7 +955,13 @@
:to="{ name: 'logs' }"
class="block w-fit text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md mb-2"
>
View Logs
Logs
</router-link>
<router-link
:to="{ name: 'test' }"
class="block w-fit text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md mb-2"
>
Test Page
</router-link>
</section>
</main>

2
src/views/HelpOnboardingView.vue

@ -114,5 +114,5 @@ import { Component, Vue } from "vue-facing-decorator";
import QuickNav from "../components/QuickNav.vue";
@Component({ components: { QuickNav } })
export default class Help extends Vue {}
export default class HelpOnboardingView extends Vue {}
</script>

2
src/views/HelpView.vue

@ -586,7 +586,7 @@ import {
} from "../db/index";
@Component({ components: { QuickNav } })
export default class Help extends Vue {
export default class HelpView extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void;
$router!: Router;

31
src/views/TestView.vue

@ -163,25 +163,25 @@
<div class="mt-8">
<h2 class="text-xl font-bold mb-4">SQL Operations</h2>
<div class="mb-4">
<div class="flex gap-2 mb-2">
<button
class="text-sm text-blue-600 hover:text-blue-800 underline"
@click="
sqlQuery = 'SELECT * FROM sqlite_master WHERE type=\'table\';'
"
>
All Tables
</button>
</div>
<div>
<textarea
v-model="sqlQuery"
class="w-full h-32 p-2 border border-gray-300 rounded-md font-mono"
placeholder="Enter your SQL query here..."
></textarea>
</div>
<div class="flex gap-2 mt-2">
<button
class="text-sm text-blue-600 hover:text-blue-800 underline"
@click="
sqlQuery = 'SELECT * FROM sqlite_master WHERE type=\'table\';'
"
>
All Tables
</button>
</div>
<div class="mb-4">
<div class="mt-4">
<button
class="font-bold capitalize bg-slate-500 text-white px-3 py-2 rounded-md mr-2"
@click="executeSql"
@ -307,7 +307,6 @@ import { AppString, NotificationIface } from "../constants/app";
import { db, retrieveSettingsForActiveAccount } from "../db/index";
import * as vcLib from "../libs/crypto/vc";
import * as cryptoLib from "../libs/crypto";
import databaseService from "../services/database";
import {
PeerSetup,
@ -323,6 +322,7 @@ import {
SHARED_PHOTO_BASE64_KEY,
} from "../libs/util";
import { logger } from "../utils/logger";
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
const inputFileNameRef = ref<Blob>();
const TEST_PAYLOAD = {
@ -535,12 +535,13 @@ export default class Help extends Vue {
}
async executeSql() {
const platformService = PlatformServiceFactory.getInstance();
try {
const isSelect = this.sqlQuery.trim().toLowerCase().startsWith("select");
if (isSelect) {
this.sqlResult = await databaseService.query(this.sqlQuery);
this.sqlResult = await platformService.dbQuery(this.sqlQuery);
} else {
this.sqlResult = await databaseService.run(this.sqlQuery);
this.sqlResult = await platformService.dbExec(this.sqlQuery);
}
logger.log("SQL Result:", this.sqlResult);
} catch (error) {

Loading…
Cancel
Save