Files
supabase/apps/studio/data/database/schemas-query.ts
T
Joshen Lim 1baaded0bb Consolidate execute-sql-query into execute-sql-mutation (#46944)
## 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
2026-06-16 00:07:16 +08:00

62 lines
1.8 KiB
TypeScript

import pgMeta from '@supabase/pg-meta'
import { QueryClient, useQuery } from '@tanstack/react-query'
import { z } from 'zod'
import { databaseKeys } from './keys'
import { executeSql } from '@/data/sql/execute-sql-mutation'
import { ResponseError, UseCustomQueryOptions } from '@/types'
export type SchemasVariables = {
projectRef?: string
connectionString?: string | null
}
export type Schema = z.infer<typeof pgMeta.schemas.zod>
const pgMetaSchemasList = pgMeta.schemas.list()
export type SchemasData = z.infer<typeof pgMetaSchemasList.zod>
export type SchemasError = ResponseError
export async function getSchemas(
{ projectRef, connectionString }: SchemasVariables,
signal?: AbortSignal
) {
const { result } = await executeSql(
{
projectRef,
connectionString,
sql: pgMetaSchemasList.sql,
queryKey: ['schemas'],
},
signal
)
return result
}
export const useSchemasQuery = <TData = SchemasData>(
{ projectRef, connectionString }: SchemasVariables,
{ enabled = true, ...options }: UseCustomQueryOptions<SchemasData, SchemasError, TData> = {}
) =>
useQuery<SchemasData, SchemasError, TData>({
queryKey: databaseKeys.schemas(projectRef),
queryFn: ({ signal }) => getSchemas({ projectRef, connectionString }, signal),
enabled: enabled && typeof projectRef !== 'undefined',
...options,
})
export function invalidateSchemasQuery(client: QueryClient, projectRef: string | undefined) {
return client.invalidateQueries({ queryKey: databaseKeys.schemas(projectRef) })
}
export function prefetchSchemas(
client: QueryClient,
{ projectRef, connectionString }: SchemasVariables
) {
return client.fetchQuery({
queryKey: databaseKeys.schemas(projectRef),
queryFn: ({ signal }) => getSchemas({ projectRef, connectionString }, signal),
})
}