Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

feat: add "Copy as INSERT" to data grid context menu (#166)

t8y2bd08d9865d9d
diff --git a/src/components/grid/DataGrid.vue b/src/components/grid/DataGrid.vue
index ead0d7463b..ad5a7de5f3 100644
--- a/src/components/grid/DataGrid.vue
+++ b/src/components/grid/DataGrid.vue
@@ -1101,6 +1101,18 @@ function copyRow() {
copyText(JSON.stringify(obj, null, 2));
}
+function copyRowAsInsert() {
+ if (!contextCell.value) return;
+ const item = getRowItem(contextCell.value.rowId);
+ if (!item) return;
+ const cols = props.result.columns.map((c) => quoteIdent(c)).join(", ");
+ const vals = item.data.map((v) => escapeVal(v)).join(", ");
+ const table = props.tableMeta
+ ? (props.tableMeta.schema ? `${quoteIdent(props.tableMeta.schema)}.` : "") + quoteIdent(props.tableMeta.tableName)
+ : "table_name";
+ copyText(`INSERT INTO ${table} (${cols}) VALUES (${vals});`);
+}
+
function copyAll() {
const header = props.result.columns.join("\t");
const body = displayItems.value.map((item) => item.data.map((c) => formatCell(c)).join("\t")).join("\n");
@@ -1732,6 +1744,7 @@ defineExpose({
<ContextMenuContent class="w-60">
<ContextMenuItem @click="copyCell">{{ t("grid.copyCell") }}</ContextMenuItem>
<ContextMenuItem @click="copyRow">{{ t("grid.copyRow") }}</ContextMenuItem>
+ <ContextMenuItem @click="copyRowAsInsert">{{ t("grid.copyRowInsert") }}</ContextMenuItem>
<ContextMenuItem @click="copyAll">{{ t("grid.copyAll") }}</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem v-if="contextCell" @click="openTranspose(contextCell.rowIndex)">
diff --git a/src/i18n/locales/en.ts b/src/i18n/locales/en.ts
index a3d5e2cb18..7763159278 100644
--- a/src/i18n/locales/en.ts
+++ b/src/i18n/locales/en.ts
@@ -172,6 +172,7 @@ export default {
noFilteredRowsDescription: "Adjust the search text or row status filter.",
copyCell: "Copy Cell",
copyRow: "Copy Row (JSON)",
+ copyRowInsert: "Copy as INSERT",
copyAll: "Copy All (TSV)",
copySelectionTsv: "Copy Selection (TSV)",
copySelectionCsv: "Copy Selection (CSV)",
diff --git a/src/i18n/locales/zh-CN.ts b/src/i18n/locales/zh-CN.ts
index f66a07a477..1633f29015 100644
--- a/src/i18n/locales/zh-CN.ts
+++ b/src/i18n/locales/zh-CN.ts
@@ -171,6 +171,7 @@ export default {
noFilteredRowsDescription: "调整搜索词或状态筛选试试。",
copyCell: "复制单元格",
copyRow: "复制行 (JSON)",
+ copyRowInsert: "复制为 INSERT 语句",
copyAll: "复制全部 (TSV)",
copySelectionTsv: "复制选区 (TSV)",
copySelectionCsv: "复制选区 (CSV)",