mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 10:55:06 +03:00
* Add connection string syntax * Add more description to pooling modes * Fix * Test * Fix * Sm wording change * Update apps/studio/components/interfaces/Settings/Database/ConnectionPooling/ConnectionPooling.tsx * prettier --------- Co-authored-by: Terry Sutton <saltcod@gmail.com> Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import { get } from 'data/fetchers'
|
|
import { ResponseError } from 'types'
|
|
import { databaseKeys } from './keys'
|
|
import { components } from 'data/api'
|
|
|
|
export type PoolingConfigurationVariables = {
|
|
projectRef?: string
|
|
}
|
|
|
|
export type PoolingConfiguration = components['schemas']['PgbouncerConfigResponse']
|
|
|
|
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/pgbouncer`, {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
if (error) throw 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,
|
|
}
|
|
)
|