Files
supabase/apps/studio/data/database/backups-query.ts
Ivan Vasilov 436bdb10ae chore: Move the studio app to apps/studio (#18915)
* Move all studio files from /studio to /apps/studio.

* Move studio specific prettier ignores.

* Fix the ui references from studio.

* Fix the css imports.

* Fix all package.json issues.

* Fix the prettier setup for the studio app.

* Add .turbo folder to prettierignore.

* Fix the github workflows.
2023-11-15 12:38:55 +01:00

38 lines
1.2 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 BackupsVariables = {
projectRef?: string
}
export type DatabaseBackup = components['schemas']['Backup']
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) throw 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> = {}
) =>
useQuery<BackupsData, BackupsError, TData>(
databaseKeys.backups(projectRef),
({ signal }) => getBackups({ projectRef }, signal),
{ enabled: enabled && typeof projectRef !== 'undefined', ...options }
)