mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
## 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
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { getIndexWorkerStatusSQL } from '@supabase/pg-meta'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { authKeys } from './keys'
|
|
import { executeSql } from '@/data/sql/execute-sql-mutation'
|
|
import { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
type IndexWorkerStatusVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
type IndexWorkerStatusData = {
|
|
is_in_progress: boolean
|
|
}
|
|
export type IndexWorkerStatusError = ResponseError
|
|
|
|
export async function getIndexWorkerStatus(
|
|
{ projectRef, connectionString }: IndexWorkerStatusVariables,
|
|
signal?: AbortSignal
|
|
): Promise<IndexWorkerStatusData> {
|
|
const sql = getIndexWorkerStatusSQL()
|
|
|
|
const { result } = await executeSql<IndexWorkerStatusData[]>(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
sql,
|
|
queryKey: ['index-worker-status'],
|
|
},
|
|
signal
|
|
)
|
|
|
|
return result[0]
|
|
}
|
|
|
|
export const useIndexWorkerStatusQuery = <TData = IndexWorkerStatusData>(
|
|
{ projectRef, connectionString }: IndexWorkerStatusVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<IndexWorkerStatusData, IndexWorkerStatusError, TData> = {}
|
|
) =>
|
|
useQuery<IndexWorkerStatusData, IndexWorkerStatusError, TData>({
|
|
queryKey: authKeys.indexWorkerStatus(projectRef),
|
|
queryFn: ({ signal }) =>
|
|
getIndexWorkerStatus(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
},
|
|
signal
|
|
),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|