mirror of
https://github.com/supabase/supabase.git
synced 2026-06-28 11:33:52 -04:00
1baaded0bb
## 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
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { safeSql } from '@supabase/pg-meta/src/pg-format'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { databaseKeys } from './keys'
|
|
import { executeSql } from '@/data/sql/execute-sql-mutation'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { PROJECT_STATUS } from '@/lib/constants'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type SupamonitorEnabledVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
export async function getSupamonitorEnabled({
|
|
projectRef,
|
|
connectionString,
|
|
}: SupamonitorEnabledVariables) {
|
|
const { result } = await executeSql<{ libraries: string }[]>({
|
|
projectRef,
|
|
connectionString,
|
|
sql: safeSql`SELECT current_setting('shared_preload_libraries', true) AS libraries`,
|
|
})
|
|
|
|
const libraries = result[0]?.libraries ?? ''
|
|
return libraries.split(',').some((lib) => lib.trim() === 'supamonitor')
|
|
}
|
|
|
|
export type SupamonitorEnabledData = Awaited<ReturnType<typeof getSupamonitorEnabled>>
|
|
export type SupamonitorEnabledError = ResponseError
|
|
|
|
export const useSupamonitorEnabledQuery = <TData = SupamonitorEnabledData>(
|
|
{ projectRef, connectionString }: SupamonitorEnabledVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<SupamonitorEnabledData, SupamonitorEnabledError, TData> = {}
|
|
) => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const isActive = project?.status === PROJECT_STATUS.ACTIVE_HEALTHY
|
|
|
|
return useQuery<SupamonitorEnabledData, SupamonitorEnabledError, TData>({
|
|
queryKey: databaseKeys.supamonitorEnabled(projectRef),
|
|
queryFn: () => getSupamonitorEnabled({ projectRef, connectionString }),
|
|
enabled: enabled && typeof projectRef !== 'undefined' && isActive,
|
|
...options,
|
|
})
|
|
}
|