mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 20:35:07 +03:00
* Add custom types for queries, mutations and infinite queries. * Migrate all queries to use the new type. * Migrate all infinite queries to useCustomInfiniteQueryOptions. * Migrate all mutations to use useCustomMutationOptions. * Add type to all imports in `types` folder.
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import minify from 'pg-minify'
|
|
|
|
import { executeSql } from 'data/sql/execute-sql-query'
|
|
import type { ResponseError, UseCustomQueryOptions } from 'types'
|
|
import { QUEUES_SCHEMA } from './database-queues-toggle-postgrest-mutation'
|
|
import { databaseQueuesKeys } from './keys'
|
|
|
|
export type DatabaseQueuesVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
// [Joshen] Check if all the relevant functions exist to indicate whether PGMQ has been exposed through PostgREST
|
|
const queueSqlQuery = minify(/**SQL */ `
|
|
SELECT exists (select schema_name FROM information_schema.schemata WHERE schema_name = '${QUEUES_SCHEMA}');
|
|
`)
|
|
|
|
export async function getDatabaseQueuesExposePostgrestStatus({
|
|
projectRef,
|
|
connectionString,
|
|
}: DatabaseQueuesVariables) {
|
|
if (!projectRef) throw new Error('Project ref is required')
|
|
|
|
const { result } = await executeSql({
|
|
projectRef,
|
|
connectionString,
|
|
sql: queueSqlQuery,
|
|
})
|
|
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,
|
|
})
|