mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
## 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
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { getMaxConnectionsSql } from '@supabase/pg-meta'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { databaseKeys } from './keys'
|
|
import { executeSql } from '@/data/sql/execute-sql-mutation'
|
|
import { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type MaxConnectionsVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
table?: string
|
|
schema?: string
|
|
}
|
|
|
|
export async function getMaxConnections(
|
|
{ projectRef, connectionString }: MaxConnectionsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const sql = getMaxConnectionsSql()
|
|
|
|
const { result } = await executeSql(
|
|
{ projectRef, connectionString, sql, queryKey: ['max-connections'] },
|
|
signal
|
|
)
|
|
|
|
const connections = parseInt(result[0].max_connections)
|
|
|
|
return { maxConnections: connections }
|
|
}
|
|
|
|
export type MaxConnectionsData = Awaited<ReturnType<typeof getMaxConnections>>
|
|
export type MaxConnectionsError = ResponseError
|
|
|
|
export const useMaxConnectionsQuery = <TData = MaxConnectionsData>(
|
|
{ projectRef, connectionString }: MaxConnectionsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<MaxConnectionsData, MaxConnectionsError, TData> = {}
|
|
) =>
|
|
useQuery<MaxConnectionsData, MaxConnectionsError, TData>({
|
|
queryKey: databaseKeys.maxConnections(projectRef),
|
|
queryFn: ({ signal }) => getMaxConnections({ projectRef, connectionString }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|