refactor: Modularize database page into components and composables

- Extract types to types/database.ts
- Create composables: useDatabaseApi, useDataTable, useQueryExecutor
- Create components: DatabaseSidebar, DataTable, FilterBar, SchemaInfo,
  QueryEditor, QueryColumnsBar, DatabaseStats, TablePagination
- Add horizontal scroll to DataTable with sticky checkbox column
- Configure @ path alias in vite and tsconfig
- Reduce DatabasePage.vue from 1548 to 314 lines
This commit is contained in:
2026-02-13 13:21:52 -06:00
parent 421b184829
commit da6111bd1f
17 changed files with 1629 additions and 1370 deletions

View File

@@ -0,0 +1,53 @@
import { ref } from 'vue'
const API_BASE = 'http://localhost:4101/api/database'
export function useQueryExecutor() {
const queryText = ref('')
const queryResult = ref<any[] | null>(null)
const queryError = ref<string | null>(null)
const queryLoading = ref(false)
async function executeQuery() {
if (!queryText.value.trim()) return
queryLoading.value = true
queryError.value = null
queryResult.value = null
try {
const res = await fetch(`${API_BASE}/query`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: queryText.value })
})
const result = await res.json()
if (!res.ok) {
queryError.value = result.error || 'Query failed'
} else {
queryResult.value = result.rows
}
} catch (e: any) {
queryError.value = e.message
} finally {
queryLoading.value = false
}
}
function reset() {
queryText.value = ''
queryResult.value = null
queryError.value = null
}
return {
queryText,
queryResult,
queryError,
queryLoading,
executeQuery,
reset
}
}