feat(app): handle SQL export and tray updates

This commit is contained in:
t8y2
2026-05-18 18:39:59 +08:00
parent b01c17e709
commit b2be49367c
12 changed files with 153 additions and 11 deletions
+1 -2
View File
@@ -365,8 +365,7 @@ async function openSqlFile() {
async function openSqlFilePath(path: string) {
if (!isTauriRuntime()) return;
try {
const { readTextFile } = await import("@tauri-apps/plugin-fs");
const content = await readTextFile(path);
const content = await api.readExternalSqlFile(path);
const connectionId =
connectionStore.activeConnectionId || activeTab.value?.connectionId || connectionStore.connections[0]?.id || "";
const connection = connectionId ? connectionStore.getConfig(connectionId) : undefined;
@@ -43,6 +43,7 @@ const tableError = ref<string | null>(null);
const includeStructure = ref(true);
const includeData = ref(true);
const includeObjects = ref(true);
const dropTableIfExists = ref(false);
// Export state
const isExporting = ref(false);
@@ -197,6 +198,7 @@ async function startExport() {
includeStructure: includeStructure.value,
includeData: includeData.value,
includeObjects: includeObjects.value,
dropTableIfExists: dropTableIfExists.value,
batchSize: 1000,
};
@@ -240,6 +242,7 @@ function resetState() {
includeStructure.value = true;
includeData.value = true;
includeObjects.value = true;
dropTableIfExists.value = false;
isExporting.value = false;
exportProgress.value = null;
exportDone.value = false;
@@ -415,6 +418,15 @@ watch(open, async (val) => {
<Square v-else class="w-3.5 h-3.5 text-muted-foreground/40 shrink-0" />
{{ t("databaseExport.includeStructure") }}
</div>
<div
class="flex items-center gap-2 text-xs"
:class="includeStructure ? 'cursor-pointer' : 'cursor-not-allowed text-muted-foreground/50'"
@click="includeStructure && (dropTableIfExists = !dropTableIfExists)"
>
<CheckSquare v-if="dropTableIfExists && includeStructure" class="w-3.5 h-3.5 text-primary shrink-0" />
<Square v-else class="w-3.5 h-3.5 text-muted-foreground/40 shrink-0" />
{{ t("databaseExport.dropTableIfExists") }}
</div>
<div class="flex items-center gap-2 cursor-pointer text-xs" @click="includeData = !includeData">
<CheckSquare v-if="includeData" class="w-3.5 h-3.5 text-primary shrink-0" />
<Square v-else class="w-3.5 h-3.5 text-muted-foreground/40 shrink-0" />
+1
View File
@@ -1173,6 +1173,7 @@ export default {
databaseExport: {
title: "Export Database",
includeStructure: "Table structure (DDL)",
dropTableIfExists: "Add DROP TABLE IF EXISTS before DDL",
includeData: "Table data (INSERT)",
includeObjects: "Views / Procedures / Functions",
tableSelection: "Tables",
+1
View File
@@ -1078,6 +1078,7 @@ export default {
databaseExport: {
title: "Exportar base de datos",
includeStructure: "Estructura de tablas (DDL)",
dropTableIfExists: "Agregar DROP TABLE IF EXISTS antes del DDL",
includeData: "Datos de tablas (INSERT)",
includeObjects: "Vistas / Procedimientos / Funciones",
tableSelection: "Tablas",
+1
View File
@@ -1150,6 +1150,7 @@ export default {
databaseExport: {
title: "导出数据库",
includeStructure: "表结构 (DDL)",
dropTableIfExists: "导出前添加 DROP TABLE IF EXISTS",
includeData: "表数据 (INSERT)",
includeObjects: "视图 / 存储过程 / 函数",
tableSelection: "选择表",
+1
View File
@@ -102,6 +102,7 @@ export const executeSqlFile = forward("executeSqlFile");
export const cancelSqlFileExecution = forward("cancelSqlFileExecution");
export const listenSqlFileProgress = forward("listenSqlFileProgress");
export const pendingOpenSqlFiles = forward("pendingOpenSqlFiles");
export const readExternalSqlFile = forward("readExternalSqlFile");
// Data Transfer
export const startTransfer = forward("startTransfer");
+4
View File
@@ -482,6 +482,10 @@ export async function pendingOpenSqlFiles(): Promise<string[]> {
return [];
}
export async function readExternalSqlFile(_path: string): Promise<string> {
throw new Error("Opening external SQL file paths is only available in the desktop app");
}
// ---------------------------------------------------------------------------
// Data Transfer
// ---------------------------------------------------------------------------
+5
View File
@@ -112,6 +112,10 @@ export async function pendingOpenSqlFiles(): Promise<string[]> {
return invoke("pending_open_sql_files");
}
export async function readExternalSqlFile(path: string): Promise<string> {
return invoke("read_external_sql_file", { path });
}
// --- AI Conversations ---
export interface AiChatMessage {
@@ -868,6 +872,7 @@ export interface DatabaseExportRequest {
includeStructure: boolean;
includeData: boolean;
includeObjects: boolean;
dropTableIfExists?: boolean;
batchSize: number;
}