mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 23:29:08 +03:00
* chore: aggressive prefetching * use abort signals in prefetchers * move encrypted columns to react-query * prefetching for filter and sort applied * prefetch remaining entity types * prefetch tables in more places * prefetch editor page on project panel * add feature flag * fix typescript * nit * Nit * fix imports * remove views check on encrypted schemas * use fetchQuery instead of prefetchQuery * fix useEncryptedColumnsQuery ts error * filter by schema on encrypted columns * don't use pg_get_tabledef for foreign tables * Remove unnecesary import --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import pgMeta from '@supabase/pg-meta'
|
|
import { QueryClient, UseQueryOptions } from '@tanstack/react-query'
|
|
import { z } from 'zod'
|
|
|
|
import {
|
|
executeSql,
|
|
ExecuteSqlData,
|
|
ExecuteSqlError,
|
|
useExecuteSqlQuery,
|
|
} from 'data/sql/execute-sql-query'
|
|
import { sqlKeys } from 'data/sql/keys'
|
|
|
|
export type SchemasVariables = {
|
|
projectRef?: string
|
|
connectionString?: string
|
|
}
|
|
|
|
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 = ExecuteSqlError
|
|
|
|
export const useSchemasQuery = <TData = SchemasData>(
|
|
{ projectRef, connectionString }: SchemasVariables,
|
|
options: UseQueryOptions<ExecuteSqlData, SchemasError, TData> = {}
|
|
) =>
|
|
useExecuteSqlQuery(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
sql: pgMetaSchemasList.sql,
|
|
queryKey: ['schemas', 'list'],
|
|
},
|
|
{
|
|
select(data) {
|
|
return data.result
|
|
},
|
|
...options,
|
|
}
|
|
)
|
|
|
|
export function invalidateSchemasQuery(client: QueryClient, projectRef: string | undefined) {
|
|
return client.invalidateQueries(sqlKeys.query(projectRef, ['schemas', 'list']))
|
|
}
|
|
|
|
export function prefetchSchemas(
|
|
client: QueryClient,
|
|
{ projectRef, connectionString }: SchemasVariables
|
|
) {
|
|
return client.fetchQuery(sqlKeys.query(projectRef, ['schemas', 'list']), ({ signal }) =>
|
|
executeSql(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
sql: pgMetaSchemasList.sql,
|
|
queryKey: ['schemas', 'list'],
|
|
},
|
|
signal
|
|
)
|
|
)
|
|
}
|