mirror of
https://github.com/ruvnet/RuVector.git
synced 2026-05-24 22:15:18 +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>
72 lines
2 KiB
TypeScript
72 lines
2 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { executeSql, ExecuteSqlError } from '../sql/execute-sql-query'
|
|
import { databaseKeys } from './keys'
|
|
import { UseCustomQueryOptions } from 'types'
|
|
|
|
type GetViewDefinitionArgs = {
|
|
id?: number
|
|
}
|
|
|
|
// [Joshen] Eventually move this into entity-definition-query
|
|
export const getViewDefinitionSql = ({ id }: GetViewDefinitionArgs) => {
|
|
if (!id) {
|
|
throw new Error('id is required')
|
|
}
|
|
|
|
const sql = /* SQL */ `
|
|
with table_info as (
|
|
select
|
|
n.nspname::text as schema,
|
|
c.relname::text as name,
|
|
to_regclass(concat('"', n.nspname, '"."', c.relname, '"')) as regclass
|
|
from pg_class c
|
|
join pg_namespace n on n.oid = c.relnamespace
|
|
where c.oid = ${id}
|
|
)
|
|
select pg_get_viewdef(t.regclass, true) as definition
|
|
from table_info t
|
|
`.trim()
|
|
|
|
return sql
|
|
}
|
|
|
|
export type ViewDefinitionVariables = GetViewDefinitionArgs & {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
export async function getViewDefinition(
|
|
{ projectRef, connectionString, id }: ViewDefinitionVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const sql = getViewDefinitionSql({ id })
|
|
const { result } = await executeSql(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
sql,
|
|
queryKey: ['view-definition', id],
|
|
},
|
|
signal
|
|
)
|
|
|
|
return result[0].definition.trim()
|
|
}
|
|
|
|
export type ViewDefinitionData = string
|
|
export type ViewDefinitionError = ExecuteSqlError
|
|
|
|
export const useViewDefinitionQuery = <TData = ViewDefinitionData>(
|
|
{ projectRef, connectionString, id }: ViewDefinitionVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<ViewDefinitionData, ViewDefinitionError, TData> = {}
|
|
) =>
|
|
useQuery<ViewDefinitionData, ViewDefinitionError, TData>({
|
|
queryKey: databaseKeys.viewDefinition(projectRef, id),
|
|
queryFn: ({ signal }) => getViewDefinition({ projectRef, connectionString, id }, signal),
|
|
enabled:
|
|
enabled && typeof projectRef !== 'undefined' && typeof id !== 'undefined' && !isNaN(id),
|
|
...options,
|
|
})
|