mirror of
https://github.com/supabase/supabase.git
synced 2026-07-07 06:24:18 +08:00
* Convert the SQL query to react-query. Minor refactor. * Make the widget better in case of a API call failure.
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { UseQueryOptions } from '@tanstack/react-query'
|
|
import { ExecuteSqlData, useExecuteSqlQuery } from '../sql/execute-sql-query'
|
|
|
|
export const getMaxConnectionsQuery = () => {
|
|
const sql = /* SQL */ `show max_connections`
|
|
|
|
return sql
|
|
}
|
|
|
|
export type MaxConnectionsVariables = {
|
|
projectRef?: string
|
|
connectionString?: string
|
|
table?: string
|
|
schema?: string
|
|
}
|
|
|
|
export type MaxConnectionsData = { maxConnections: number }
|
|
export type MaxConnectionsError = unknown
|
|
|
|
export const useMaxConnectionsQuery = <TData extends MaxConnectionsData = MaxConnectionsData>(
|
|
{ projectRef, connectionString }: MaxConnectionsVariables,
|
|
options: UseQueryOptions<ExecuteSqlData, MaxConnectionsError, TData> = {}
|
|
) => {
|
|
return useExecuteSqlQuery<TData>(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
sql: getMaxConnectionsQuery(),
|
|
queryKey: ['max-connections'],
|
|
},
|
|
{
|
|
select: (data: { result: { max_connections: string }[] }) => {
|
|
const connections = parseInt(data.result[0].max_connections)
|
|
return { maxConnections: connections } as any
|
|
},
|
|
...options,
|
|
}
|
|
)
|
|
}
|