mirror of
https://github.com/ruvnet/RuVector.git
synced 2026-05-25 15:03:46 +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>
95 lines
2.7 KiB
TypeScript
95 lines
2.7 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { Query } from '@supabase/pg-meta/src/query'
|
|
import { executeSql } from 'data/sql/execute-sql-query'
|
|
import { RoleImpersonationState, wrapWithRoleImpersonation } from 'lib/role-impersonation'
|
|
import { isRoleImpersonationEnabled } from 'state/role-impersonation-state'
|
|
import type { ResponseError, UseCustomMutationOptions } from 'types'
|
|
import { tableRowKeys } from './keys'
|
|
|
|
export type TableRowUpdateVariables = {
|
|
projectRef: string
|
|
connectionString?: string | null
|
|
table: { id: number; name: string; schema?: string }
|
|
configuration: { identifiers: any }
|
|
payload: any
|
|
enumArrayColumns: string[]
|
|
returning?: boolean
|
|
roleImpersonationState?: RoleImpersonationState
|
|
}
|
|
|
|
export function getTableRowUpdateSql({
|
|
table,
|
|
configuration,
|
|
payload,
|
|
returning = false,
|
|
enumArrayColumns,
|
|
}: Pick<
|
|
TableRowUpdateVariables,
|
|
'table' | 'payload' | 'configuration' | 'enumArrayColumns' | 'returning'
|
|
>) {
|
|
return new Query()
|
|
.from(table.name, table.schema ?? undefined)
|
|
.update(payload, { returning, enumArrayColumns })
|
|
.match(configuration.identifiers)
|
|
.toSql()
|
|
}
|
|
|
|
export async function updateTableRow({
|
|
projectRef,
|
|
connectionString,
|
|
table,
|
|
payload,
|
|
configuration,
|
|
enumArrayColumns,
|
|
returning,
|
|
roleImpersonationState,
|
|
}: TableRowUpdateVariables) {
|
|
const sql = wrapWithRoleImpersonation(
|
|
getTableRowUpdateSql({ table, configuration, payload, enumArrayColumns, returning }),
|
|
roleImpersonationState
|
|
)
|
|
|
|
const { result } = await executeSql({
|
|
projectRef,
|
|
connectionString,
|
|
sql,
|
|
isRoleImpersonationEnabled: isRoleImpersonationEnabled(roleImpersonationState?.role),
|
|
queryKey: ['table-row-update', table.id],
|
|
})
|
|
|
|
return result
|
|
}
|
|
|
|
type TableRowUpdateData = Awaited<ReturnType<typeof updateTableRow>>
|
|
|
|
export const useTableRowUpdateMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<TableRowUpdateData, ResponseError, TableRowUpdateVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation<TableRowUpdateData, ResponseError, TableRowUpdateVariables>({
|
|
mutationFn: (vars) => updateTableRow(vars),
|
|
async onSuccess(data, variables, context) {
|
|
const { projectRef, table } = variables
|
|
await queryClient.invalidateQueries({
|
|
queryKey: tableRowKeys.tableRows(projectRef, { table: { id: table.id } }),
|
|
})
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to update table row: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|