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:
53
frontend/src/composables/database/useQueryExecutor.ts
Normal file
53
frontend/src/composables/database/useQueryExecutor.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user