mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 20:35:07 +03:00
## 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
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 { 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,
|
|
})
|