mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-29 08:11:06 +00:00
feat: add "Copy as INSERT" to data grid context menu (#166)
This commit is contained in:
@@ -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)">
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -171,6 +171,7 @@ export default {
|
||||
noFilteredRowsDescription: "调整搜索词或状态筛选试试。",
|
||||
copyCell: "复制单元格",
|
||||
copyRow: "复制行 (JSON)",
|
||||
copyRowInsert: "复制为 INSERT 语句",
|
||||
copyAll: "复制全部 (TSV)",
|
||||
copySelectionTsv: "复制选区 (TSV)",
|
||||
copySelectionCsv: "复制选区 (CSV)",
|
||||
|
||||
Reference in New Issue
Block a user