Files
supabase/apps/studio/data/database/pgbouncer-config-query.ts
Joshen Lim a458977e2d 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-02-28 11:14:42 +08:00

43 lines
1.2 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import { ResponseError } from 'types'
import { databaseKeys } from './keys'
export type PgbouncerConfigVariables = {
projectRef?: string
}
export async function getPgbouncerConfig(
{ projectRef }: PgbouncerConfigVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
const { data, error } = await get('/platform/projects/{ref}/config/pgbouncer', {
params: { path: { ref: projectRef } },
signal,
})
if (error) handleError(error)
return data
}
export type PgbouncerConfigData = Awaited<ReturnType<typeof getPgbouncerConfig>>
export type PgbouncerConfigError = ResponseError
export const usePgbouncerConfigQuery = <TData = PgbouncerConfigData>(
{ projectRef }: PgbouncerConfigVariables,
{
enabled = true,
...options
}: UseQueryOptions<PgbouncerConfigData, PgbouncerConfigError, TData> = {}
) =>
useQuery<PgbouncerConfigData, PgbouncerConfigError, TData>(
databaseKeys.pgbouncerConfig(projectRef),
({ signal }) => getPgbouncerConfig({ projectRef }, signal),
{
enabled: enabled && typeof projectRef !== 'undefined',
...options,
}
)