mirror of
https://github.com/ruvnet/RuVector.git
synced 2026-05-24 13:54:31 +00:00
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>
71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
import pgMeta from '@supabase/pg-meta'
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { executeSql } from 'data/sql/execute-sql-query'
|
|
import type { ResponseError, UseCustomMutationOptions } from 'types'
|
|
import { tableKeys } from './keys'
|
|
|
|
export type CreateTableBody = {
|
|
name: string
|
|
schema?: string
|
|
comment?: string | null
|
|
}
|
|
|
|
export type TableCreateVariables = {
|
|
projectRef: string
|
|
connectionString?: string | null
|
|
// the schema is required field
|
|
payload: CreateTableBody & { schema: string }
|
|
}
|
|
|
|
export async function createTable({ projectRef, connectionString, payload }: TableCreateVariables) {
|
|
const { sql } = pgMeta.tables.create(payload)
|
|
|
|
const { result } = await executeSql<void>({
|
|
projectRef,
|
|
connectionString,
|
|
sql,
|
|
queryKey: ['table', 'create'],
|
|
})
|
|
|
|
return result
|
|
}
|
|
|
|
type TableCreateData = Awaited<ReturnType<typeof createTable>>
|
|
|
|
export const useTableCreateMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<TableCreateData, ResponseError, TableCreateVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation<TableCreateData, ResponseError, TableCreateVariables>({
|
|
mutationFn: (vars) => createTable(vars),
|
|
async onSuccess(data, variables, context) {
|
|
const { projectRef, payload } = variables
|
|
|
|
await Promise.all([
|
|
queryClient.invalidateQueries({
|
|
queryKey: tableKeys.list(projectRef, payload.schema, true),
|
|
}),
|
|
queryClient.invalidateQueries({
|
|
queryKey: tableKeys.list(projectRef, payload.schema, false),
|
|
}),
|
|
])
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to create database table: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|