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>
92 lines
2.3 KiB
TypeScript
92 lines
2.3 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { DEFAULT_QUERY_PARAMS } from 'components/interfaces/Reports/Reports.constants'
|
|
import {
|
|
BaseReportParams,
|
|
MetaQueryResponse,
|
|
ReportQuery,
|
|
} from 'components/interfaces/Reports/Reports.types'
|
|
import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
|
|
import { executeSql } from 'data/sql/execute-sql-query'
|
|
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
|
|
import { useDatabaseSelectorStateSnapshot } from 'state/database-selector'
|
|
|
|
export interface DbQueryHook<T = any> {
|
|
isLoading: boolean
|
|
isRefetching: boolean
|
|
error: string
|
|
data: T[]
|
|
params: BaseReportParams
|
|
logData?: never
|
|
runQuery: () => void
|
|
setParams?: never
|
|
changeQuery?: never
|
|
resolvedSql: string
|
|
}
|
|
|
|
// [Joshen] Atm this is being used only in query performance
|
|
const useDbQuery = ({
|
|
sql,
|
|
params = DEFAULT_QUERY_PARAMS,
|
|
where,
|
|
orderBy,
|
|
}: {
|
|
sql: ReportQuery['sql'] | string
|
|
params?: BaseReportParams
|
|
where?: string
|
|
orderBy?: string
|
|
}): DbQueryHook => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const state = useDatabaseSelectorStateSnapshot()
|
|
|
|
const { data: databases } = useReadReplicasQuery({ projectRef: project?.ref })
|
|
const connectionString = (databases || []).find(
|
|
(db) => db.identifier === state.selectedDatabaseId
|
|
)?.connectionString
|
|
const identifier = state.selectedDatabaseId
|
|
|
|
const resolvedSql = typeof sql === 'function' ? sql([]) : sql
|
|
|
|
const {
|
|
data,
|
|
error: rqError,
|
|
isLoading,
|
|
isRefetching,
|
|
refetch,
|
|
} = useQuery({
|
|
queryKey: [
|
|
'projects',
|
|
project?.ref,
|
|
'db',
|
|
{ ...params, sql: resolvedSql, identifier },
|
|
where,
|
|
orderBy,
|
|
],
|
|
queryFn: ({ signal }) => {
|
|
return executeSql(
|
|
{
|
|
projectRef: project?.ref,
|
|
connectionString: connectionString || project?.connectionString,
|
|
sql: resolvedSql,
|
|
},
|
|
signal
|
|
).then((res) => res.result) as Promise<MetaQueryResponse>
|
|
},
|
|
enabled: Boolean(resolvedSql),
|
|
refetchOnWindowFocus: false,
|
|
refetchOnReconnect: false,
|
|
})
|
|
|
|
const error = rqError || (typeof data === 'object' ? data?.error : '')
|
|
return {
|
|
error,
|
|
data,
|
|
isLoading,
|
|
isRefetching,
|
|
params,
|
|
runQuery: refetch,
|
|
resolvedSql,
|
|
}
|
|
}
|
|
|
|
export default useDbQuery
|