mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 23:29:08 +03:00
wip schema query
This commit is contained in:
1 parent
af288cb2c2
commit
c5cbeea86b
1 file changed
+44
@@ -0,0 +1,44 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { get, handleError } from 'data/fetchers'
|
||||
import { analyticsKeys } from './keys'
|
||||
|
||||
type CollectionSchemaVariables = {
|
||||
projectRef: string
|
||||
collectionToken: string
|
||||
}
|
||||
|
||||
export async function getCollectionSchema(
|
||||
{ projectRef, collectionToken }: CollectionSchemaVariables,
|
||||
signal?: AbortSignal
|
||||
) {
|
||||
if (!projectRef) {
|
||||
throw new Error('projectRef is required')
|
||||
}
|
||||
|
||||
// TODO: Remove type cast when codegen types are fixed
|
||||
const { data, error } = await get(
|
||||
`/platform/projects/{ref}/analytics/warehouse/collections/{collectionToken}/schema` as any,
|
||||
{
|
||||
params: { path: { ref: projectRef, collectionToken } },
|
||||
signal,
|
||||
} as any
|
||||
)
|
||||
|
||||
if (error) handleError(error)
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
export type CollectionSchemaData = Awaited<ReturnType<typeof getCollectionSchema>>
|
||||
|
||||
export const useCollectionSchemaQuery = (
|
||||
{ projectRef, collectionToken }: CollectionSchemaVariables,
|
||||
{ enabled }: { enabled: boolean } = { enabled: true }
|
||||
) =>
|
||||
useQuery(
|
||||
analyticsKeys.collectionSchema(projectRef, collectionToken),
|
||||
({ signal }) => getCollectionSchema({ projectRef, collectionToken }, signal),
|
||||
{
|
||||
enabled: enabled && !!projectRef && !!collectionToken,
|
||||
}
|
||||
)
|
||||
Reference in new issue
Block a user