ruvector/studio/data/config/disk-breakdown-query.ts
rUv 814f595995 feat(studio): Add complete RuVector Studio application
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>
2025-12-06 23:04:48 +00:00

63 lines
1.6 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { executeSql } from 'data/sql/execute-sql-query'
import type { ResponseError, UseCustomQueryOptions } from 'types'
import { configKeys } from './keys'
export type DiskBreakdownVariables = {
projectRef?: string
connectionString?: string | null
}
type DiskBreakdownResult = {
db_size_bytes: number
wal_size_bytes: number
}
export async function getDiskBreakdown(
{ projectRef, connectionString }: DiskBreakdownVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('Project ref is required')
if (!connectionString) throw new Error('Connection string is required')
const { result } = await executeSql(
{
projectRef,
connectionString,
sql: `
SELECT
(
SELECT
SUM(pg_database_size(pg_database.datname)) AS db_size_bytes
FROM
pg_database
),
(
SELECT SUM(size)
FROM
pg_ls_waldir()
) AS wal_size_bytes`,
},
signal
)
return result[0] as DiskBreakdownResult
}
export type DiskBreakdownData = Awaited<ReturnType<typeof getDiskBreakdown>>
export type DiskBreakdownError = ResponseError
export const useDiskBreakdownQuery = <TData = DiskBreakdownData>(
{ projectRef, connectionString }: DiskBreakdownVariables,
{
enabled = true,
...options
}: UseCustomQueryOptions<DiskBreakdownData, DiskBreakdownError, TData> = {}
) =>
useQuery<DiskBreakdownData, DiskBreakdownError, TData>({
queryKey: configKeys.diskBreakdown(projectRef),
queryFn: ({ signal }) => getDiskBreakdown({ projectRef, connectionString }, signal),
enabled: enabled && typeof projectRef !== 'undefined',
...options,
})