From abed7b275feaca84ac0140e3a80ae5a29d09d271 Mon Sep 17 00:00:00 2001 From: sun Date: Mon, 9 Dec 2024 15:08:33 +0800 Subject: [PATCH] fix: load table in selected db (#458) * fix: load curr db table * feat: db refresh * fix: db limit * fix: watch works only inside module * fix: empty db config * feat: soft refresh --- src/router/routes/modules/dashboard.ts | 1 + src/store/modules/logquery/index.ts | 28 +++++++++++++++++-- src/views/dashboard/logs/query/index.vue | 34 +++++++++++++++--------- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/router/routes/modules/dashboard.ts b/src/router/routes/modules/dashboard.ts index 35bc2b5b..b8041579 100644 --- a/src/router/routes/modules/dashboard.ts +++ b/src/router/routes/modules/dashboard.ts @@ -94,6 +94,7 @@ const DASHBOARD: AppRouteRecordRaw = { component: () => import('@/views/dashboard/logs/query/index.vue'), name: 'log-query', meta: { + ignoreCache: true, locale: 'menu.dashboard.logquery', requiresAuth: false, icon: 'log', diff --git a/src/store/modules/logquery/index.ts b/src/store/modules/logquery/index.ts index 20e5b335..97d99d68 100644 --- a/src/store/modules/logquery/index.ts +++ b/src/store/modules/logquery/index.ts @@ -126,8 +126,24 @@ const useLogQueryStore = defineStore('logQuery', () => { const mergeColumn = useLocalStorage('logquery-merge-column', true) const showKeys = useLocalStorage('logquery-show-keys', true) - + const appStore = useAppStore() function getSchemas() { + const db = appStore.database + const tableCatalog = db?.split('-').slice(0, -1).join('-') + const tableSchema = db?.split('-').slice(-1).join('-') + + const conditions = [] + if (tableCatalog) { + conditions.push(`table_catalog='${tableCatalog}'`) + } + if (tableSchema) { + conditions.push(`table_schema='${tableSchema}'`) + } + let where = '' + if (conditions.length) { + where = `WHERE ${conditions.join(' and ')}` + } + return editorAPI .runSQL( `SELECT @@ -137,7 +153,7 @@ const useLogQueryStore = defineStore('logQuery', () => { data_type FROM information_schema.columns - Where table_schema != 'information_schema' + ${where} ORDER BY table_name ` @@ -257,6 +273,13 @@ const useLogQueryStore = defineStore('logQuery', () => { } }) + function reset() { + inputTableName.value = '' + sql.value = '' + editingSql.value = '' + queryForm.conditions = [] + rows.value = [] + } return { sql, query, @@ -288,6 +311,7 @@ const useLogQueryStore = defineStore('logQuery', () => { dataLoadFlag, showKeys, queryColumns, + reset, } }) export default useLogQueryStore diff --git a/src/views/dashboard/logs/query/index.vue b/src/views/dashboard/logs/query/index.vue index 4531d6c3..d48cc938 100644 --- a/src/views/dashboard/logs/query/index.vue +++ b/src/views/dashboard/logs/query/index.vue @@ -1,5 +1,5 @@