mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 02:15:05 +03:00
74 lines
2.0 KiB
TypeScript
74 lines
2.0 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { databaseKeys } from './keys'
|
|
import type { components } from '@/data/api'
|
|
import { handleError, patch } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomMutationOptions } from '@/types'
|
|
|
|
export type PgbouncerConfigurationUpdateVariables = {
|
|
ref: string
|
|
} & Pick<
|
|
components['schemas']['UpdatePgbouncerConfigBody'],
|
|
'default_pool_size' | 'max_client_conn' | 'ignore_startup_parameters'
|
|
>
|
|
|
|
export async function updatePgbouncerConfiguration({
|
|
ref,
|
|
default_pool_size,
|
|
max_client_conn,
|
|
ignore_startup_parameters,
|
|
}: PgbouncerConfigurationUpdateVariables) {
|
|
if (!ref) return console.error('Project ref is required')
|
|
|
|
const { data, error } = await patch('/platform/projects/{ref}/config/pgbouncer', {
|
|
params: { path: { ref } },
|
|
body: {
|
|
default_pool_size,
|
|
max_client_conn,
|
|
ignore_startup_parameters,
|
|
},
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type PgbouncerConfigurationUpdateData = Awaited<ReturnType<typeof updatePgbouncerConfiguration>>
|
|
|
|
export const usePgbouncerConfigurationUpdateMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<
|
|
PgbouncerConfigurationUpdateData,
|
|
ResponseError,
|
|
PgbouncerConfigurationUpdateVariables
|
|
>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation<
|
|
PgbouncerConfigurationUpdateData,
|
|
ResponseError,
|
|
PgbouncerConfigurationUpdateVariables
|
|
>({
|
|
mutationFn: (vars) => updatePgbouncerConfiguration(vars),
|
|
async onSuccess(data, variables, context) {
|
|
const { ref } = variables
|
|
await queryClient.invalidateQueries({ queryKey: databaseKeys.pgbouncerConfig(ref) })
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to update PgBouncer configuration: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|