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(desktop): add create actions to tree groups

t8y290c618dac602
diff --git a/apps/desktop/src/components/sidebar/TreeItem.vue b/apps/desktop/src/components/sidebar/TreeItem.vue
index be2d068ef0..a3146da2bc 100644
--- a/apps/desktop/src/components/sidebar/TreeItem.vue
+++ b/apps/desktop/src/components/sidebar/TreeItem.vue
@@ -1436,7 +1436,7 @@ const supportsTruncate = computed(() => {
const canCreateTable = computed(() => {
const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;
return (
- (props.node.type === "database" || props.node.type === "schema") &&
+ (props.node.type === "database" || props.node.type === "schema" || props.node.type === "group-tables") &&
!!props.node.database &&
supportsTableStructureEditing(config?.db_type)
);
@@ -1798,6 +1798,21 @@ function createTable() {
queryStore.openTableStructure(node.connectionId, node.database, node.schema, "");
}
+function createView() {
+ const node = props.node;
+ if (!node.connectionId || !node.database) return;
+ connectionStore.activeConnectionId = node.connectionId;
+ const viewName = node.schema ? `${node.schema}.new_view` : "new_view";
+ const tabId = queryStore.createTab(
+ node.connectionId,
+ node.database,
+ t("contextMenu.createView"),
+ "query",
+ node.schema,
+ );
+ queryStore.updateSql(tabId, `CREATE VIEW ${viewName} AS\nSELECT\n *\nFROM table_name;\n`);
+}
+
async function saveFileContent(content: string, defaultFileName: string, filterName: string, filterExt: string) {
if (isTauriRuntime()) {
const { save } = await import("@tauri-apps/plugin-dialog");
@@ -3054,6 +3069,18 @@ function treeItemMenuItems(): ContextMenuItem[] {
});
items.push({ label: "", separator: true });
}
+ const hasGroupCreateAction =
+ (node.type === "group-tables" && canCreateTable.value) ||
+ (node.type === "group-views" && !!node.connectionId && !!node.database);
+ if (node.type === "group-tables" && canCreateTable.value) {
+ items.push({ label: t("contextMenu.createTable"), action: createTable, icon: Plus });
+ }
+ if (node.type === "group-views" && node.connectionId && node.database) {
+ items.push({ label: t("contextMenu.createView"), action: createView, icon: Plus });
+ }
+ if (hasGroupCreateAction) {
+ items.push({ label: "", separator: true });
+ }
if (node.type !== "saved-sql-root" && node.type !== "saved-sql-folder" && node.type !== "group-partitions") {
items.push({
label: t("contextMenu.refreshChildren"),
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index 85c5c1fe3b..584e765e7d 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -939,6 +939,7 @@ export default {
saveStructure: "Save SQL",
exportStructureCopied: "Structure copied",
createTable: "Create Table",
+ createView: "Create View",
dropTable: "Drop Table",
emptyTable: "Empty Table",
truncateTable: "Truncate Table",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index acd7cb112f..e24f13cb4a 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -836,6 +836,7 @@ export default {
saveStructure: "Guardar SQL",
exportStructureCopied: "Estructura copiada",
createTable: "Crear tabla",
+ createView: "Crear vista",
dropTable: "Eliminar tabla",
emptyTable: "Vaciar tabla",
truncateTable: "Truncar tabla",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index 0b9a516e19..227f505e4e 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -920,6 +920,7 @@ export default {
saveStructure: "保存 SQL",
exportStructureCopied: "表结构已复制",
createTable: "新建表",
+ createView: "新建视图",
dropTable: "删除表",
emptyTable: "清空数据",
truncateTable: "截断表",
diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts
index e97ae2d6a4..17d024c9a5 100644
--- a/apps/desktop/src/i18n/locales/zh-TW.ts
+++ b/apps/desktop/src/i18n/locales/zh-TW.ts
@@ -920,6 +920,7 @@ export default {
saveStructure: "儲存 SQL",
exportStructureCopied: "資料表結構已複製",
createTable: "建立資料表",
+ createView: "建立檢視",
dropTable: "刪除資料表",
emptyTable: "清空資料",
truncateTable: "截斷資料表",