diff --git a/src/db/index.ts b/src/db/index.ts index 444a98db..27256da0 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -144,9 +144,8 @@ export async function updateDefaultSettings( // console.log("Database version:", db.verno); await safeOpenDatabase(); } catch (openError: unknown) { - console.error("Failed to open database:", openError); - const errorMessage = openError instanceof Error ? openError.message : String(openError); - throw new Error(`Database connection failed: ${errorMessage}. Please try again or restart the app.`); + console.error("Failed to open database:", openError, String(openError)); + throw new Error(`The database connection failed. We recommend you try again or restart the app.`); } const result = await db.settings.update(MASTER_SETTINGS_KEY, settingsChanges); return result; @@ -155,7 +154,7 @@ export async function updateDefaultSettings( if (error instanceof Error) { throw error; // Re-throw if it's already an Error with a message } else { - throw new Error(`Failed to update settings: ${error}`); + throw new Error(`Failed to update settings. We recommend you try again or restart the app.`); } } } diff --git a/src/views/TestView.vue b/src/views/TestView.vue index 619096dc..10bf8bfb 100644 --- a/src/views/TestView.vue +++ b/src/views/TestView.vue @@ -161,6 +161,38 @@ +
+

SQL Operations

+
+
+ +
+ +
+ +
+ +
+
+

Result:

+
{{ JSON.stringify(sqlResult, null, 2) }}
+
+
+

Image Sharing

Populates the "shared-photo" view as if they used "share_target". @@ -271,6 +303,7 @@ 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, @@ -316,6 +349,10 @@ export default class Help extends Vue { peerSetup?: PeerSetup; userName?: string; + // for SQL operations + sqlQuery = ""; + sqlResult: any = null; + cryptoLib = cryptoLib; async mounted() { @@ -492,5 +529,28 @@ export default class Help extends Vue { ); logger.log("decoded", decoded); } + + async executeSql() { + try { + const isSelect = this.sqlQuery.trim().toLowerCase().startsWith('select'); + if (isSelect) { + this.sqlResult = await databaseService.query(this.sqlQuery); + } else { + this.sqlResult = await databaseService.run(this.sqlQuery); + } + console.log("SQL Result:", this.sqlResult); + } catch (error) { + console.error("SQL Error:", error); + this.$notify( + { + group: "alert", + type: "danger", + title: "SQL Error", + text: error instanceof Error ? error.message : String(error), + }, + 5000 + ); + } + } }