mirror of
https://github.com/ruvnet/RuVector.git
synced 2026-05-25 06:36:37 +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>
77 lines
2.3 KiB
TypeScript
77 lines
2.3 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { executeSql } from 'data/sql/execute-sql-query'
|
|
import { tableKeys } from 'data/tables/keys'
|
|
import type { ResponseError, UseCustomMutationOptions } from 'types'
|
|
import { databaseQueuesKeys } from './keys'
|
|
|
|
export type DatabaseQueueCreateVariables = {
|
|
projectRef: string
|
|
connectionString?: string | null
|
|
name: string
|
|
type: 'basic' | 'partitioned' | 'unlogged'
|
|
enableRls: boolean
|
|
configuration?: {
|
|
partitionInterval?: number
|
|
retentionInterval?: number
|
|
}
|
|
}
|
|
|
|
export async function createDatabaseQueue({
|
|
projectRef,
|
|
connectionString,
|
|
name,
|
|
type,
|
|
enableRls,
|
|
configuration,
|
|
}: DatabaseQueueCreateVariables) {
|
|
const { partitionInterval, retentionInterval } = configuration ?? {}
|
|
|
|
const query =
|
|
type === 'partitioned'
|
|
? `select from pgmq.create_partitioned('${name}', '${partitionInterval}', '${retentionInterval}');`
|
|
: type === 'unlogged'
|
|
? `SELECT pgmq.create_unlogged('${name}');`
|
|
: `SELECT pgmq.create('${name}');`
|
|
|
|
const { result } = await executeSql({
|
|
projectRef,
|
|
connectionString,
|
|
sql: `${query} ${enableRls ? `alter table pgmq."q_${name}" enable row level security;` : ''}`.trim(),
|
|
queryKey: databaseQueuesKeys.create(),
|
|
})
|
|
|
|
return result
|
|
}
|
|
|
|
type DatabaseQueueCreateData = Awaited<ReturnType<typeof createDatabaseQueue>>
|
|
|
|
export const useDatabaseQueueCreateMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<DatabaseQueueCreateData, ResponseError, DatabaseQueueCreateVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation<DatabaseQueueCreateData, ResponseError, DatabaseQueueCreateVariables>({
|
|
mutationFn: (vars) => createDatabaseQueue(vars),
|
|
async onSuccess(data, variables, context) {
|
|
const { projectRef } = variables
|
|
await queryClient.invalidateQueries({ queryKey: databaseQueuesKeys.list(projectRef) })
|
|
queryClient.invalidateQueries({ queryKey: tableKeys.list(projectRef, 'pgmq') })
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to create database queue: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|