Files
supabase/apps/studio/data/database/backups-query.ts
angelico 14562e9c8a chore: init useIsOrioleDbInAws (#35325)
* chore: check for cloud provider in useIsOrioleDb

* chore: introduce useIsOrioleDbInAwsNew instead

* chore: consolidate to using useIsOrioleDb

* chore: selectively include useIsOrioleDbInAwsNew in conditionals

* fix: prettier

* fix: incorrect cloud provider

* fix: update conditional instead

* fix: prettier

* Simplify logic

* Smol fix

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-04-30 15:29:48 +08:00

46 lines
1.4 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import type { components } from 'data/api'
import { get, handleError } from 'data/fetchers'
import { useIsOrioleDbInAws } from 'hooks/misc/useSelectedProject'
import type { ResponseError } from 'types'
import { databaseKeys } from './keys'
export type BackupsVariables = {
projectRef?: string
}
export type DatabaseBackup = components['schemas']['BackupsResponse']['backups'][number]
export async function getBackups({ projectRef }: BackupsVariables, signal?: AbortSignal) {
if (!projectRef) throw new Error('Project ref is required')
const { data, error } = await get(`/platform/database/{ref}/backups`, {
params: { path: { ref: projectRef } },
signal,
})
if (error) handleError(error)
return data
}
export type BackupsData = Awaited<ReturnType<typeof getBackups>>
export type BackupsError = ResponseError
export const useBackupsQuery = <TData = BackupsData>(
{ projectRef }: BackupsVariables,
{ enabled = true, ...options }: UseQueryOptions<BackupsData, BackupsError, TData> = {}
) => {
// [Joshen] Check for specifically false to account for project not loaded yet
const isOrioleDbInAws = useIsOrioleDbInAws()
return useQuery<BackupsData, BackupsError, TData>(
databaseKeys.backups(projectRef),
({ signal }) => getBackups({ projectRef }, signal),
{
enabled: enabled && !isOrioleDbInAws && typeof projectRef !== 'undefined',
...options,
}
)
}