mirror of
https://github.com/supabase/supabase.git
synced 2026-06-30 12:29:05 -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.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { getOngoingQueriesSql } from '@supabase/pg-meta'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { sqlKeys } from './keys'
|
|
import { executeSql } from '@/data/sql/execute-sql-mutation'
|
|
import { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
type OngoingQuery = {
|
|
pid: number
|
|
query: string
|
|
query_start: string
|
|
}
|
|
|
|
export type OngoingQueriesVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
export async function getOngoingQueries(
|
|
{ projectRef, connectionString }: OngoingQueriesVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const sql = getOngoingQueriesSql()
|
|
|
|
const { result } = await executeSql(
|
|
{ projectRef, connectionString, sql, queryKey: ['ongoing-queries'] },
|
|
signal
|
|
)
|
|
|
|
return (result ?? []).filter((x: OngoingQuery) => !x.query.startsWith(sql)) as OngoingQuery[]
|
|
}
|
|
|
|
export type OngoingQueriesData = Awaited<ReturnType<typeof getOngoingQueries>>
|
|
export type OngoingQueriesError = ResponseError
|
|
|
|
export const useOngoingQueriesQuery = <TData = OngoingQueriesData>(
|
|
{ projectRef, connectionString }: OngoingQueriesVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<OngoingQueriesData, OngoingQueriesError, TData> = {}
|
|
) =>
|
|
useQuery<OngoingQueriesData, OngoingQueriesError, TData>({
|
|
queryKey: sqlKeys.ongoingQueries(projectRef),
|
|
queryFn: ({ signal }) => getOngoingQueries({ projectRef, connectionString }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|