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
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import pgMeta from '@supabase/pg-meta'
|
|
import type { PGForeignTable } from '@supabase/pg-meta'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { foreignTableKeys } from './keys'
|
|
import { executeSql } from '@/data/sql/execute-sql-mutation'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type ForeignTablesVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
schema?: string
|
|
}
|
|
|
|
export async function getForeignTables(
|
|
{ projectRef, connectionString, schema }: ForeignTablesVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const { result } = await executeSql(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
sql: pgMeta.foreignTables.list(schema ? { includedSchemas: [schema] } : undefined).sql,
|
|
queryKey: ['foreign-tables', schema],
|
|
},
|
|
signal
|
|
)
|
|
|
|
return result as PGForeignTable[]
|
|
}
|
|
|
|
export type ForeignTablesData = Awaited<ReturnType<typeof getForeignTables>>
|
|
export type ForeignTablesError = ResponseError
|
|
|
|
export const useForeignTablesQuery = <TData = ForeignTablesData>(
|
|
{ projectRef, connectionString, schema }: ForeignTablesVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<ForeignTablesData, ForeignTablesError, TData> = {}
|
|
) =>
|
|
useQuery<ForeignTablesData, ForeignTablesError, TData>({
|
|
queryKey: schema
|
|
? foreignTableKeys.listBySchema(projectRef, schema)
|
|
: foreignTableKeys.list(projectRef),
|
|
queryFn: ({ signal }) => getForeignTables({ projectRef, connectionString, schema }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|