mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 22:29:11 +03:00
add pgbouncer config and status queries (#33772)
* add queries * use different keys * move folder * rm old files * Small refactoir --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
This commit is contained in:
1 parent
476aa77c58
commit
68b077a661
6 files changed
+94
-2
No files matched your search
@@ -1,6 +1,4 @@
|
||||
export const configKeys = {
|
||||
pgBouncerStatus: (projectRef: string | undefined) =>
|
||||
['projects', projectRef, 'pgbouncer'] as const,
|
||||
settings: (projectRef: string | undefined) => ['projects', projectRef, 'settings'] as const,
|
||||
settingsV2: (projectRef: string | undefined) => ['projects', projectRef, 'settings-v2'] as const,
|
||||
api: (projectRef: string | undefined) => ['projects', projectRef, 'settings', 'api'] as const,
|
||||
|
||||
@@ -35,4 +35,8 @@ export const databaseKeys = {
|
||||
['projects', projectRef, 'database-size'] as const,
|
||||
maxConnections: (projectRef: string | undefined) =>
|
||||
['projects', projectRef, 'max-connections'] as const,
|
||||
pgbouncerStatus: (projectRef: string | undefined) =>
|
||||
['projects', projectRef, 'pgbouncer', 'status'] as const,
|
||||
pgbouncerConfig: (projectRef: string | undefined) =>
|
||||
['projects', projectRef, 'pgbouncer', 'config'] as const,
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
|
||||
import { get, handleError } from 'data/fetchers'
|
||||
import { ResponseError } from 'types'
|
||||
import { databaseKeys } from './keys'
|
||||
|
||||
export type ProjectPgbouncerConfigVariables = {
|
||||
projectRef?: string
|
||||
}
|
||||
|
||||
export async function getProjectPgbouncerConfig(
|
||||
{ projectRef }: ProjectPgbouncerConfigVariables,
|
||||
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 ProjectPgbouncerConfigData = Awaited<ReturnType<typeof getProjectPgbouncerConfig>>
|
||||
export type ProjectPgbouncerConfigError = ResponseError
|
||||
|
||||
export const useProjectPgbouncerConfigQuery = <TData = ProjectPgbouncerConfigData>(
|
||||
{ projectRef }: ProjectPgbouncerConfigVariables,
|
||||
{
|
||||
enabled = true,
|
||||
...options
|
||||
}: UseQueryOptions<ProjectPgbouncerConfigData, ProjectPgbouncerConfigError, TData> = {}
|
||||
) =>
|
||||
useQuery<ProjectPgbouncerConfigData, ProjectPgbouncerConfigError, TData>(
|
||||
databaseKeys.pgbouncerConfig(projectRef),
|
||||
({ signal }) => getProjectPgbouncerConfig({ projectRef }, signal),
|
||||
{
|
||||
enabled: enabled && typeof projectRef !== 'undefined',
|
||||
...options,
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,42 @@
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
|
||||
import { get, handleError } from 'data/fetchers'
|
||||
import { ResponseError } from 'types'
|
||||
import { databaseKeys } from './keys'
|
||||
|
||||
export type ProjectPgbouncerStatusVariables = {
|
||||
projectRef?: string
|
||||
}
|
||||
|
||||
export async function getProjectPgbouncerStatus(
|
||||
{ projectRef }: ProjectPgbouncerStatusVariables,
|
||||
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 ProjectPgbouncerStatusData = Awaited<ReturnType<typeof getProjectPgbouncerStatus>>
|
||||
export type ProjectPgbouncerStatusError = ResponseError
|
||||
|
||||
export const useProjectPgbouncerStatusQuery = <TData = ProjectPgbouncerStatusData>(
|
||||
{ projectRef }: ProjectPgbouncerStatusVariables,
|
||||
{
|
||||
enabled = true,
|
||||
...options
|
||||
}: UseQueryOptions<ProjectPgbouncerStatusData, ProjectPgbouncerStatusError, TData> = {}
|
||||
) =>
|
||||
useQuery<ProjectPgbouncerStatusData, ProjectPgbouncerStatusError, TData>(
|
||||
databaseKeys.pgbouncerStatus(projectRef),
|
||||
({ signal }) => getProjectPgbouncerStatus({ projectRef }, signal),
|
||||
{
|
||||
enabled: enabled && typeof projectRef !== 'undefined',
|
||||
...options,
|
||||
}
|
||||
)
|
||||
@@ -11,6 +11,9 @@ export type PoolingConfigurationVariables = {
|
||||
|
||||
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
|
||||
|
||||
@@ -10,6 +10,9 @@ export type PoolingConfigurationUpdateVariables = {
|
||||
ref: string
|
||||
} & components['schemas']['UpdateSupavisorConfigBody']
|
||||
|
||||
/**
|
||||
* Should rename this to Supavisor eventually since we're supporting both types of poolers
|
||||
*/
|
||||
export async function updatePoolingConfiguration({
|
||||
ref,
|
||||
pool_mode,
|
||||
|
||||
Reference in new issue
Block a user