Files
supabase/apps/studio/data/auth/index-worker-status-query.ts
Joshen Lim fc7fb50aa2 Organize pg meta queries for studio (#43562)
## Context

We reached to a consensus that we'll keep manually written queries
within the `pg-meta` package

I'll shift queries over in several PRs but wanted to double check if the
changes here is a good folder structure

## Changes involved

- Am organizing dashboard queries in `pg-meta` based on product
  - So folder structure will be `/sql/studio/[product]/*.ts`
- Every constant will be exported directly from `pg-meta`'s index
- So consumption in dashboard will just be `import { xxx } from
'@supabase/pg-meta`

cc @avallete and @soedirgo on this one - lemme know if this is alright,
or if there's a preferred way to do this
2026-03-10 09:34:11 +07:00

56 lines
1.5 KiB
TypeScript

import { getIndexWorkerStatusSQL } from '@supabase/pg-meta'
import { useQuery } from '@tanstack/react-query'
import { executeSql, type ExecuteSqlError } from 'data/sql/execute-sql-query'
import { UseCustomQueryOptions } from 'types'
import { authKeys } from './keys'
type IndexWorkerStatusVariables = {
projectRef?: string
connectionString?: string | null
}
type IndexWorkerStatusData = {
is_in_progress: boolean
}
export type IndexWorkerStatusError = ExecuteSqlError
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,
})