Files
supabase/apps/studio/data/auth/user-search-indexes-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

58 lines
1.5 KiB
TypeScript

import { getIndexStatusesSQL } 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 UsersIndexStatusesVariables = {
projectRef?: string
connectionString?: string | null
}
type UsersIndexStatusesData = {
index_name: string
is_valid: boolean
is_ready: boolean
}[]
export type UsersIndexStatusesError = ExecuteSqlError
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,
})