mirror of
https://github.com/supabase/supabase.git
synced 2026-10-18 23:59: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>
70 lines
2.2 KiB
TypeScript
70 lines
2.2 KiB
TypeScript
import { QueryClient, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import { executeSql } from 'data/sql/execute-sql-query'
|
|
import type { ResponseError } from 'types'
|
|
import { encryptedColumnKeys } from './keys'
|
|
|
|
export type EncryptedColumnsVariables = {
|
|
projectRef?: string
|
|
connectionString?: string
|
|
schema?: string
|
|
tableName?: string
|
|
}
|
|
|
|
export async function getEncryptedColumns(
|
|
{ projectRef, connectionString, schema, tableName }: EncryptedColumnsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!tableName) return []
|
|
|
|
try {
|
|
const encryptedColumns = await executeSql(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
sql: `select column_name as name from information_schema.columns where table_schema = '${schema}' and table_name = 'decrypted_${tableName}' and column_name like 'decrypted_%'`,
|
|
queryKey: ['encrypted-columns', tableName],
|
|
},
|
|
signal
|
|
)
|
|
return encryptedColumns.result.map((column: any) => column.name.split('decrypted_')[1])
|
|
} catch (error) {
|
|
console.error('Error fetching encrypted columns', error)
|
|
return []
|
|
}
|
|
}
|
|
|
|
export type EncryptedColumnsData = Awaited<ReturnType<typeof getEncryptedColumns>>
|
|
export type EncryptedColumnsError = ResponseError
|
|
|
|
export const useEncryptedColumnsQuery = <TData = EncryptedColumnsData>(
|
|
{ projectRef, connectionString, schema, tableName }: EncryptedColumnsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseQueryOptions<EncryptedColumnsData, EncryptedColumnsError, TData> = {}
|
|
) =>
|
|
useQuery<EncryptedColumnsData, EncryptedColumnsError, TData>(
|
|
encryptedColumnKeys.list(projectRef, schema, tableName),
|
|
({ signal }) =>
|
|
getEncryptedColumns({ projectRef, connectionString, schema, tableName }, signal),
|
|
{ enabled: enabled && typeof projectRef !== 'undefined', ...options }
|
|
)
|
|
|
|
export function prefetchEncryptedColumns(
|
|
client: QueryClient,
|
|
{ projectRef, connectionString, schema, tableName }: EncryptedColumnsVariables
|
|
) {
|
|
return client.fetchQuery(encryptedColumnKeys.list(projectRef, schema, tableName), ({ signal }) =>
|
|
getEncryptedColumns(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
schema,
|
|
tableName,
|
|
},
|
|
signal
|
|
)
|
|
)
|
|
}
|