Files
supabase/apps/studio/data/database-queues/database-queues-expose-postgrest-status-query.ts
Joshen Lim 1baaded0bb Consolidate execute-sql-query into execute-sql-mutation (#46944)
## 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
2026-06-16 00:07:16 +08:00

44 lines
1.4 KiB
TypeScript

import { getQueuesExposePostgrestStatusSQL } from '@supabase/pg-meta'
import { useQuery } from '@tanstack/react-query'
import { databaseQueuesKeys } from './keys'
import { executeSql } from '@/data/sql/execute-sql-mutation'
import type { ResponseError, UseCustomQueryOptions } from '@/types'
export type DatabaseQueuesVariables = {
projectRef?: string
connectionString?: string | null
}
export async function getDatabaseQueuesExposePostgrestStatus({
projectRef,
connectionString,
}: DatabaseQueuesVariables) {
if (!projectRef) throw new Error('Project ref is required')
const sql = getQueuesExposePostgrestStatusSQL()
const { result } = await executeSql({
projectRef,
connectionString,
sql,
})
return result[0].exists as boolean
}
export type DatabaseQueueData = boolean
export type DatabaseQueueError = ResponseError
export const useQueuesExposePostgrestStatusQuery = <TData = DatabaseQueueData>(
{ projectRef, connectionString }: DatabaseQueuesVariables,
{
enabled = true,
...options
}: UseCustomQueryOptions<DatabaseQueueData, DatabaseQueueError, TData> = {}
) =>
useQuery<DatabaseQueueData, DatabaseQueueError, TData>({
queryKey: databaseQueuesKeys.exposePostgrestStatus(projectRef),
queryFn: () => getDatabaseQueuesExposePostgrestStatus({ projectRef, connectionString }),
enabled: enabled && typeof projectRef !== 'undefined',
...options,
})