mirror of
https://github.com/supabase/supabase.git
synced 2026-06-29 03:50:30 -04:00
1baaded0bb
## Context Just some clean up as I was going through stuff - `useExecuteSqlQuery` is deprecated and not used at all - As such `execute-sql-query` is technically irrelevant, the more relevant file is `execute-sql-mutation` - Hence opting to consolidate `execute-sql-query` into `execute-sql-mutation` - Also removing `ExecuteSqlError` since its just re-exporting the `ResponseError` type There's a lot of file changes but its essentially just updating the importing statements across the files
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { getDatabaseSizeSql } from '@supabase/pg-meta'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { databaseKeys } from './keys'
|
|
import { executeSql } from '@/data/sql/execute-sql-mutation'
|
|
import { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type DatabaseSizeVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
export async function getDatabaseSize(
|
|
{ projectRef, connectionString }: DatabaseSizeVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const sql = getDatabaseSizeSql()
|
|
|
|
const { result } = await executeSql(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
sql,
|
|
queryKey: ['database-size'],
|
|
},
|
|
signal
|
|
)
|
|
|
|
const dbSize = result?.[0]?.db_size
|
|
if (typeof dbSize !== 'number') {
|
|
throw new Error('Error fetching dbSize')
|
|
}
|
|
|
|
return dbSize
|
|
}
|
|
|
|
export type DatabaseSizeData = Awaited<ReturnType<typeof getDatabaseSize>>
|
|
export type DatabaseSizeError = ResponseError
|
|
|
|
export const useDatabaseSizeQuery = <TData = DatabaseSizeData>(
|
|
{ projectRef, connectionString }: DatabaseSizeVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<DatabaseSizeData, DatabaseSizeError, TData> = {}
|
|
) =>
|
|
useQuery<DatabaseSizeData, DatabaseSizeError, TData>({
|
|
queryKey: databaseKeys.databaseSize(projectRef),
|
|
queryFn: ({ signal }) => getDatabaseSize({ projectRef, connectionString }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|