diff --git a/apps/studio/data/config/keys.ts b/apps/studio/data/config/keys.ts index 020ebe43270..b9e286c8ec0 100644 --- a/apps/studio/data/config/keys.ts +++ b/apps/studio/data/config/keys.ts @@ -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, diff --git a/apps/studio/data/database/keys.ts b/apps/studio/data/database/keys.ts index a76aee30bff..84550d6fe2b 100644 --- a/apps/studio/data/database/keys.ts +++ b/apps/studio/data/database/keys.ts @@ -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, } diff --git a/apps/studio/data/database/pgbouncer-config-query.ts b/apps/studio/data/database/pgbouncer-config-query.ts new file mode 100644 index 00000000000..d3deadb9e33 --- /dev/null +++ b/apps/studio/data/database/pgbouncer-config-query.ts @@ -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> +export type ProjectPgbouncerConfigError = ResponseError + +export const useProjectPgbouncerConfigQuery = ( + { projectRef }: ProjectPgbouncerConfigVariables, + { + enabled = true, + ...options + }: UseQueryOptions = {} +) => + useQuery( + databaseKeys.pgbouncerConfig(projectRef), + ({ signal }) => getProjectPgbouncerConfig({ projectRef }, signal), + { + enabled: enabled && typeof projectRef !== 'undefined', + ...options, + } + ) diff --git a/apps/studio/data/database/pgbouncer-status-query.ts b/apps/studio/data/database/pgbouncer-status-query.ts new file mode 100644 index 00000000000..623808b292c --- /dev/null +++ b/apps/studio/data/database/pgbouncer-status-query.ts @@ -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> +export type ProjectPgbouncerStatusError = ResponseError + +export const useProjectPgbouncerStatusQuery = ( + { projectRef }: ProjectPgbouncerStatusVariables, + { + enabled = true, + ...options + }: UseQueryOptions = {} +) => + useQuery( + databaseKeys.pgbouncerStatus(projectRef), + ({ signal }) => getProjectPgbouncerStatus({ projectRef }, signal), + { + enabled: enabled && typeof projectRef !== 'undefined', + ...options, + } + ) diff --git a/apps/studio/data/database/pooling-configuration-query.ts b/apps/studio/data/database/pooling-configuration-query.ts index 006bcde9676..9f58ebad7c5 100644 --- a/apps/studio/data/database/pooling-configuration-query.ts +++ b/apps/studio/data/database/pooling-configuration-query.ts @@ -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 diff --git a/apps/studio/data/database/pooling-configuration-update-mutation.ts b/apps/studio/data/database/pooling-configuration-update-mutation.ts index 9795ec7e722..f02db60d97b 100644 --- a/apps/studio/data/database/pooling-configuration-update-mutation.ts +++ b/apps/studio/data/database/pooling-configuration-update-mutation.ts @@ -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,