mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 20:05:06 +03:00
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { databaseKeys } from './keys'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
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
|
|
}: UseCustomQueryOptions<PgbouncerStatusData, PgbouncerStatusError, TData> = {}
|
|
) =>
|
|
useQuery<PgbouncerStatusData, PgbouncerStatusError, TData>({
|
|
queryKey: databaseKeys.pgbouncerStatus(projectRef),
|
|
queryFn: ({ signal }) => getPgbouncerStatus({ projectRef }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|