Skip to content

Commit

Permalink
fix: load table in selected db (#458)
Browse files Browse the repository at this point in the history
* fix: load curr db table

* feat: db refresh

* fix: db limit

* fix: watch works only inside module

* fix: empty db config

* feat: soft refresh
  • Loading branch information
sunchanglong authored Dec 9, 2024
1 parent c31c66d commit abed7b2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/router/routes/modules/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
28 changes: 26 additions & 2 deletions src/store/modules/logquery/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -137,7 +153,7 @@ const useLogQueryStore = defineStore('logQuery', () => {
data_type
FROM
information_schema.columns
Where table_schema != 'information_schema'
${where}
ORDER BY
table_name
`
Expand Down Expand Up @@ -257,6 +273,13 @@ const useLogQueryStore = defineStore('logQuery', () => {
}
})

function reset() {
inputTableName.value = ''
sql.value = ''
editingSql.value = ''
queryForm.conditions = []
rows.value = []
}
return {
sql,
query,
Expand Down Expand Up @@ -288,6 +311,7 @@ const useLogQueryStore = defineStore('logQuery', () => {
dataLoadFlag,
showKeys,
queryColumns,
reset,
}
})
export default useLogQueryStore
34 changes: 22 additions & 12 deletions src/views/dashboard/logs/query/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="pug">
.container
.container(:key="containerKey")
div(style="padding: 0; background-color: var(--color-neutral-2); margin: 0")
Toolbar
SQLBuilder(
Expand Down Expand Up @@ -64,7 +64,7 @@
const { dataStatusMap } = storeToRefs(useUserStore())
const { checkTables } = useDataBaseStore()
const { getSchemas, getRelativeRange } = useLogQueryStore()
const { getSchemas, getRelativeRange, reset } = useLogQueryStore()
const {
rows,
editorType,
Expand All @@ -87,16 +87,26 @@
return `${queryNum.value}_${tableIndex.value}`
})
onActivated(async () => {
await Promise.all([
(async () => {
if (!dataStatusMap.value.tables) {
await fetchDatabases()
await checkTables()
}
})(),
])
})
Promise.all([
(async () => {
if (!dataStatusMap.value.tables) {
await fetchDatabases()
await checkTables()
}
})(),
])
const appStore = useAppStore()
const containerKey = ref('')
watch(
() => appStore.database,
() => {
containerKey.value = String(Date.now())
reset()
getSchemas()
// setTimeout(() => window.location.reload(), 1500)
}
)
</script>

<style lang="less">
Expand Down

0 comments on commit abed7b2

Please sign in to comment.