Files
supabase/apps/studio/data/database/pgbouncer-status-query.ts
T
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 PgbouncerStatusVariables = {
projectRef?: string
}
export async function getPgbouncerStatus(
{ projectRef }: PgbouncerStatusVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
const { data, error } = await get('/platform/projects/{ref}/config/pgbouncer/status', {
params: { path: { ref: projectRef } },
signal,
})
if (error) handleError(error)
return data
}
export type PgbouncerStatusData = Awaited<ReturnType<typeof getPgbouncerStatus>>
export type PgbouncerStatusError = ResponseError
export const usePgbouncerStatusQuery = <TData = PgbouncerStatusData>(
{ projectRef }: PgbouncerStatusVariables,
{
enabled = true,
...options
}: UseQueryOptions<PgbouncerStatusData, PgbouncerStatusError, TData> = {}
) =>
useQuery<PgbouncerStatusData, PgbouncerStatusError, TData>(
databaseKeys.pgbouncerStatus(projectRef),
({ signal }) => getPgbouncerStatus({ projectRef }, signal),
{
enabled: enabled && typeof projectRef !== 'undefined',
...options,
}
)