ruvector/studio/data/content/sql-folder-contents-query.ts
rUv 814f595995 feat(studio): Add complete RuVector Studio application
Major additions:
- Complete Next.js studio application with 1600+ components
- Docker support (Dockerfile.combined, docker-compose.yml)
- GCP deployment documentation and benchmarks
- SQL benchmark scripts for performance testing
- Sentry integration for monitoring
- Comprehensive test suite and mocks

Studio features:
- Dashboard and admin interfaces
- Data visualization components
- Authentication and user management
- API integration with RuVector backend
- Static data and public assets

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-06 23:04:48 +00:00

70 lines
2.2 KiB
TypeScript

import { useInfiniteQuery } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import type { ResponseError, UseCustomInfiniteQueryOptions } from 'types'
import { contentKeys } from './keys'
import { SNIPPET_PAGE_LIMIT } from './sql-folders-query'
export type SQLSnippetFolderContentsVariables = {
projectRef?: string
folderId?: string
cursor?: string
name?: string
sort?: 'name' | 'inserted_at'
}
export async function getSQLSnippetFolderContents(
{ projectRef, folderId, cursor, sort, name }: SQLSnippetFolderContentsVariables,
signal?: AbortSignal
) {
if (typeof projectRef === 'undefined') throw new Error('projectRef is required')
if (typeof folderId === 'undefined') throw new Error('folderId is required')
const sortOrder = sort === 'name' ? 'asc' : 'desc'
const { data, error } = await get('/platform/projects/{ref}/content/folders/{id}', {
params: {
path: { ref: projectRef, id: folderId },
query: {
cursor,
limit: SNIPPET_PAGE_LIMIT.toString(),
sort_by: sort,
sort_order: sortOrder,
name,
},
},
signal,
})
if (error) handleError(error)
return {
...data.data,
cursor: data.cursor,
}
}
export type SQLSnippetFolderContentsData = Awaited<ReturnType<typeof getSQLSnippetFolderContents>>
export type SQLSnippetFolderContentsError = ResponseError
export const useSQLSnippetFolderContentsQuery = <TData = SQLSnippetFolderContentsData>(
{ projectRef, folderId, name, sort }: Omit<SQLSnippetFolderContentsVariables, 'cursor'>,
{
enabled = true,
...options
}: UseCustomInfiniteQueryOptions<
SQLSnippetFolderContentsData,
SQLSnippetFolderContentsError,
TData
> = {}
) =>
useInfiniteQuery<SQLSnippetFolderContentsData, SQLSnippetFolderContentsError, TData>({
queryKey: contentKeys.folderContents(projectRef, folderId, { name, sort }),
queryFn: ({ signal, pageParam }) =>
getSQLSnippetFolderContents({ projectRef, folderId, cursor: pageParam, name, sort }, signal),
enabled: enabled && typeof projectRef !== 'undefined' && typeof folderId !== 'undefined',
getNextPageParam(lastPage) {
return lastPage.cursor
},
...options,
})