- 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
54 lines
1.1 KiB
TypeScript
54 lines
1.1 KiB
TypeScript
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
|
|
}
|
|
}
|