mirror of
https://github.com/supabase/supabase.git
synced 2026-10-09 11:25:06 +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
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import { getFDWsSql } from '@supabase/pg-meta'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { fdwKeys } from './keys'
|
|
import { executeSql } from '@/data/sql/execute-sql-mutation'
|
|
import { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type FDWColumn = {
|
|
name: string
|
|
type: string
|
|
}
|
|
|
|
export type FDWTable = {
|
|
id: string
|
|
name: string
|
|
schema: string
|
|
columns: FDWColumn[]
|
|
options: string[]
|
|
}
|
|
|
|
export type FDW = {
|
|
id: number
|
|
name: string
|
|
handler: string
|
|
server_name: string
|
|
server_options: string[] | null
|
|
tables: FDWTable[]
|
|
}
|
|
|
|
export type FDWsVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
export async function getFDWs(
|
|
{ projectRef, connectionString }: FDWsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const sql = getFDWsSql()
|
|
|
|
const { result } = await executeSql(
|
|
{ projectRef, connectionString, sql, queryKey: ['fdws'] },
|
|
signal
|
|
)
|
|
|
|
return result as FDW[]
|
|
}
|
|
|
|
export type FDWsData = Awaited<ReturnType<typeof getFDWs>>
|
|
export type FDWsError = ResponseError
|
|
|
|
export const useFDWsQuery = <TData = FDWsData>(
|
|
{ projectRef, connectionString }: FDWsVariables,
|
|
{ enabled = true, ...options }: UseCustomQueryOptions<FDWsData, FDWsError, TData> = {}
|
|
) =>
|
|
useQuery<FDWsData, FDWsError, TData>({
|
|
queryKey: fdwKeys.list(projectRef),
|
|
queryFn: ({ signal }) => getFDWs({ projectRef, connectionString }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|