mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-21 10:28:44 +00:00
fix(export): use table name for single-table exports
This commit is contained in:
@@ -24,7 +24,7 @@ import { isQueryTimeoutErrorMessage } from "@/lib/sql/queryError";
|
||||
import type { SqlInsertDialect, SqlInsertMode } from "@/lib/export/sqlInsertMode";
|
||||
import { revealExportedPath } from "@/lib/export/exportPath";
|
||||
import { translateBackendError } from "@/i18n/backend-errors";
|
||||
import { loadSavedDatabaseExportOptions, MAX_SPLIT_SQL_PART_MB, MIN_SPLIT_SQL_PART_MB, saveDatabaseExportOptions, sortDatabaseTableNames } from "@/lib/export/databaseExportOptions";
|
||||
import { databaseExportFileStem, loadSavedDatabaseExportOptions, MAX_SPLIT_SQL_PART_MB, MIN_SPLIT_SQL_PART_MB, saveDatabaseExportOptions, sortDatabaseTableNames } from "@/lib/export/databaseExportOptions";
|
||||
import { notifyExportComplete } from "@/lib/export/exportReveal";
|
||||
|
||||
const { t } = useI18n();
|
||||
@@ -403,7 +403,7 @@ async function startExport() {
|
||||
|
||||
if (isTauriRuntime()) {
|
||||
try {
|
||||
const safeName = sanitizeFileName(database.value || "database");
|
||||
const safeName = sanitizeFileName(databaseExportFileStem(database.value || "database", selectedTables.value) || "database");
|
||||
const path = await promptExportSavePath({
|
||||
defaultFileName: `${safeName}.${splitSqlOutput.value ? "zip" : "sql"}`,
|
||||
filters: [{ name: splitSqlOutput.value ? "ZIP" : "SQL", extensions: [splitSqlOutput.value ? "zip" : "sql"] }],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DEFAULT_DATABASE_EXPORT_OPTIONS, DATABASE_EXPORT_OPTIONS_STORAGE_KEY, loadSavedDatabaseExportOptions, saveDatabaseExportOptions, sortDatabaseTableNames } from "../databaseExportOptions";
|
||||
import { databaseExportFileStem, DEFAULT_DATABASE_EXPORT_OPTIONS, DATABASE_EXPORT_OPTIONS_STORAGE_KEY, loadSavedDatabaseExportOptions, saveDatabaseExportOptions, sortDatabaseTableNames } from "../databaseExportOptions";
|
||||
|
||||
function createMemoryStorage(initial: Record<string, string> = {}) {
|
||||
const store = new Map<string, string>(Object.entries(initial));
|
||||
@@ -12,6 +12,11 @@ function createMemoryStorage(initial: Record<string, string> = {}) {
|
||||
}
|
||||
|
||||
describe("databaseExportOptions", () => {
|
||||
it("uses the selected table as the filename stem for a single-table export", () => {
|
||||
expect(databaseExportFileStem("app", ["orders"])).toBe("orders");
|
||||
expect(databaseExportFileStem("app", ["orders", "users"])).toBe("app");
|
||||
expect(databaseExportFileStem("app", [])).toBe("app");
|
||||
});
|
||||
it("returns default options when storage is empty or contains invalid json", () => {
|
||||
const emptyStorage = createMemoryStorage();
|
||||
expect(loadSavedDatabaseExportOptions(emptyStorage)).toEqual(DEFAULT_DATABASE_EXPORT_OPTIONS);
|
||||
|
||||
@@ -82,3 +82,8 @@ export function sortDatabaseTableNames(names: string[]): string[] {
|
||||
// Pin the collation so the order does not shift with the OS locale.
|
||||
return [...names].sort((a, b) => a.localeCompare(b, "en", { sensitivity: "base" }));
|
||||
}
|
||||
|
||||
/** Use the selected table as the suggested filename when exporting one table. */
|
||||
export function databaseExportFileStem(database: string, selectedTables: readonly string[]): string {
|
||||
return selectedTables.length === 1 ? selectedTables[0]! : database;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user