Files
supabase/apps/studio/data/database/pooling-configuration-query.ts
Jordi EnricandJoshen Lim d10db0f735 add pgbouncer config and status queries (#33772)
* add queries

* use different keys

* move folder

* rm old files

* Small refactoir

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-02-24 11:41:35 +08:00

49 lines
1.5 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import type { components } from 'data/api'
import { get, handleError } from 'data/fetchers'
import type { ResponseError } from 'types'
import { databaseKeys } from './keys'
export type PoolingConfigurationVariables = {
projectRef?: string
}
export type PoolingConfiguration = components['schemas']['SupavisorConfigResponse']
/**
* Should rename this to Supavisor eventually since we're supporting both types of poolers
*/
export async function getPoolingConfiguration(
{ projectRef }: PoolingConfigurationVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('Project ref is required')
const { data, error } = await get(`/platform/projects/{ref}/config/supavisor`, {
params: { path: { ref: projectRef } },
signal,
})
if (error) handleError(error)
return data
}
export type PoolingConfigurationData = Awaited<ReturnType<typeof getPoolingConfiguration>>
export type PoolingConfigurationError = ResponseError
export const usePoolingConfigurationQuery = <TData = PoolingConfigurationData>(
{ projectRef }: PoolingConfigurationVariables,
{
enabled = true,
...options
}: UseQueryOptions<PoolingConfigurationData, PoolingConfigurationError, TData> = {}
) =>
useQuery<PoolingConfigurationData, PoolingConfigurationError, TData>(
databaseKeys.poolingConfiguration(projectRef),
({ signal }) => getPoolingConfiguration({ projectRef }, signal),
{
enabled: enabled && typeof projectRef !== 'undefined',
...options,
}
)