mirror of
https://github.com/supabase/supabase.git
synced 2026-07-03 22:24:28 -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
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { getTableColumnsSql } 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 TableColumn = {
|
|
schemaname: string
|
|
tablename: string
|
|
quoted_name: string
|
|
is_table: boolean
|
|
columns: any[]
|
|
}
|
|
|
|
export type TableColumnsVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
table?: string
|
|
schema?: string
|
|
}
|
|
|
|
export async function getTableColumns(
|
|
{ projectRef, connectionString, table, schema }: TableColumnsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const sql = getTableColumnsSql({ table, schema })
|
|
|
|
const { result } = await executeSql(
|
|
{ projectRef, connectionString, sql, queryKey: ['table-columns', schema, table] },
|
|
signal
|
|
)
|
|
|
|
return result as TableColumn[]
|
|
}
|
|
|
|
export type TableColumnsData = Awaited<ReturnType<typeof getTableColumns>>
|
|
export type TableColumnsError = ResponseError
|
|
|
|
export const useTableColumnsQuery = <TData = TableColumnsData>(
|
|
{ projectRef, connectionString, schema, table }: TableColumnsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<TableColumnsData, TableColumnsError, TData> = {}
|
|
) =>
|
|
useQuery<TableColumnsData, TableColumnsError, TData>({
|
|
queryKey: databaseKeys.tableColumns(projectRef, schema, table),
|
|
queryFn: ({ signal }) =>
|
|
getTableColumns({ projectRef, connectionString, schema, table }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|