mirror of
https://github.com/ruvnet/RuVector.git
synced 2026-05-24 13:54:31 +00:00
Major additions: - Complete Next.js studio application with 1600+ components - Docker support (Dockerfile.combined, docker-compose.yml) - GCP deployment documentation and benchmarks - SQL benchmark scripts for performance testing - Sentry integration for monitoring - Comprehensive test suite and mocks Studio features: - Dashboard and admin interfaces - Data visualization components - Authentication and user management - API integration with RuVector backend - Static data and public assets 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
77 lines
2 KiB
TypeScript
77 lines
2 KiB
TypeScript
import { QueryClient, useQuery } from '@tanstack/react-query'
|
|
|
|
import { executeSql, ExecuteSqlError } from '../sql/execute-sql-query'
|
|
import { tableEditorKeys } from './keys'
|
|
import { getTableEditorSql } from './table-editor-query-sql'
|
|
import { Entity } from './table-editor-types'
|
|
import { UseCustomQueryOptions } from 'types'
|
|
|
|
type TableEditorArgs = {
|
|
id?: number
|
|
}
|
|
|
|
export type TableEditorVariables = TableEditorArgs & {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
export async function getTableEditor(
|
|
{ projectRef, connectionString, id }: TableEditorVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!id) {
|
|
throw new Error('id is required')
|
|
}
|
|
|
|
const sql = getTableEditorSql(id)
|
|
const { result } = await executeSql(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
sql,
|
|
queryKey: ['table-editor', id],
|
|
},
|
|
signal
|
|
)
|
|
|
|
return (result[0]?.entity ?? null) as Entity | undefined
|
|
}
|
|
|
|
export type TableEditorData = Awaited<ReturnType<typeof getTableEditor>>
|
|
export type TableEditorError = ExecuteSqlError
|
|
|
|
export const useTableEditorQuery = <TData = TableEditorData>(
|
|
{ projectRef, connectionString, id }: TableEditorVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<TableEditorData, TableEditorError, TData> = {}
|
|
) =>
|
|
useQuery<TableEditorData, TableEditorError, TData>({
|
|
queryKey: tableEditorKeys.tableEditor(projectRef, id),
|
|
queryFn: ({ signal }) => getTableEditor({ projectRef, connectionString, id }, signal),
|
|
enabled:
|
|
enabled && typeof projectRef !== 'undefined' && typeof id !== 'undefined' && !isNaN(id),
|
|
refetchOnWindowFocus: false,
|
|
refetchOnMount: false,
|
|
staleTime: 5 * 60 * 1000,
|
|
...options,
|
|
})
|
|
|
|
export function prefetchTableEditor(
|
|
client: QueryClient,
|
|
{ projectRef, connectionString, id }: TableEditorVariables
|
|
) {
|
|
return client.fetchQuery({
|
|
queryKey: tableEditorKeys.tableEditor(projectRef, id),
|
|
queryFn: ({ signal }) =>
|
|
getTableEditor(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
id,
|
|
},
|
|
signal
|
|
),
|
|
})
|
|
}
|