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
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { getIndexStatusesSQL } 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 UsersIndexStatusesVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
type UsersIndexStatusesData = {
|
|
index_name: string
|
|
is_valid: boolean
|
|
is_ready: boolean
|
|
}[]
|
|
export type UsersIndexStatusesError = ResponseError
|
|
|
|
export async function getUserIndexStatuses(
|
|
{ projectRef, connectionString }: UsersIndexStatusesVariables,
|
|
signal?: AbortSignal
|
|
): Promise<UsersIndexStatusesData> {
|
|
const sql = getIndexStatusesSQL()
|
|
|
|
const { result } = await executeSql<UsersIndexStatusesData>(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
sql,
|
|
queryKey: ['index-statuses'],
|
|
},
|
|
signal
|
|
)
|
|
|
|
return result
|
|
}
|
|
|
|
export const useUserIndexStatusesQuery = <TData = UsersIndexStatusesData>(
|
|
{ projectRef, connectionString }: UsersIndexStatusesVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<UsersIndexStatusesData, UsersIndexStatusesError, TData> = {}
|
|
) =>
|
|
useQuery<UsersIndexStatusesData, UsersIndexStatusesError, TData>({
|
|
queryKey: authKeys.usersIndexStatuses(projectRef),
|
|
queryFn: ({ signal }) =>
|
|
getUserIndexStatuses(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
},
|
|
signal
|
|
),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|