mirror of
https://github.com/ruvnet/RuVector.git
synced 2026-05-25 15:03:46 +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>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { executeSql, ExecuteSqlError } from '../sql/execute-sql-query'
|
|
import { sqlKeys } from './keys'
|
|
import { UseCustomQueryOptions } from 'types'
|
|
|
|
type OngoingQuery = {
|
|
pid: number
|
|
query: string
|
|
query_start: string
|
|
}
|
|
|
|
export const getOngoingQueriesSql = () => {
|
|
const sql = /* SQL */ `
|
|
select pid, query, query_start from pg_stat_activity where state = 'active' and datname = 'postgres';
|
|
`.trim()
|
|
|
|
return sql
|
|
}
|
|
|
|
export type OngoingQueriesVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
export async function getOngoingQueries(
|
|
{ projectRef, connectionString }: OngoingQueriesVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const sql = getOngoingQueriesSql().trim()
|
|
|
|
const { result } = await executeSql(
|
|
{ projectRef, connectionString, sql, queryKey: ['ongoing-queries'] },
|
|
signal
|
|
)
|
|
|
|
return (result ?? []).filter((x: OngoingQuery) => !x.query.startsWith(sql)) as OngoingQuery[]
|
|
}
|
|
|
|
export type OngoingQueriesData = Awaited<ReturnType<typeof getOngoingQueries>>
|
|
export type OngoingQueriesError = ExecuteSqlError
|
|
|
|
export const useOngoingQueriesQuery = <TData = OngoingQueriesData>(
|
|
{ projectRef, connectionString }: OngoingQueriesVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<OngoingQueriesData, OngoingQueriesError, TData> = {}
|
|
) =>
|
|
useQuery<OngoingQueriesData, OngoingQueriesError, TData>({
|
|
queryKey: sqlKeys.ongoingQueries(projectRef),
|
|
queryFn: ({ signal }) => getOngoingQueries({ projectRef, connectionString }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|