Files
supabase/apps/studio/data/database/pooling-configuration-query.ts
T
Joshen Lim 9cbce8d939 Support for Dedicated Pooler in Connection Pooling (#33817)
* Init

* Initial set up for hooking up supavisor and pgbouncer

* Hook up pgbouncer status check after swapping pooler type

* Add check for nano compute for switching to pg bouncer

* Add check for ipv4 addon

* Remove expect error tag

* Add badge to select options for pooler types

* Remove statement mode

* Resolve undefined problem with react hook form

* Fix

* Update UI texts from PgBouncer to Dedicated Pooler

* Feex

* FEEX

* Fix

* Small update to UI

* Smol update
2025-03-05 15:39:02 +01:00

71 lines
2.2 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
/**
* @deprecated use useSupavisorConfigurationQuery isntead
*/
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,
}
)
/**
* Just a duplicate of usePoolingConfigurationQuery until we move everything over
*/
export const useSupavisorConfigurationQuery = <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,
}
)