ruvector/studio/components/interfaces/TableGridEditor/TableEntity.utils.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

67 lines
2.2 KiB
TypeScript

import { SupaTable } from 'components/grid/types'
import { Lint } from '../../../data/lint/lint-query'
export const getEntityLintDetails = (
entityName: string,
lintName: string,
lintLevels: ('ERROR' | 'WARN')[],
lints: Lint[],
schema: string
): { hasLint: boolean; count: number; matchingLint: Lint | null } => {
const matchingLint =
lints?.find(
(lint) =>
lint?.metadata?.name === entityName &&
lint?.metadata?.schema === schema &&
lint?.name === lintName &&
lintLevels.includes(lint?.level as 'ERROR' | 'WARN')
) || null
return {
hasLint: matchingLint !== null,
count: matchingLint ? 1 : 0,
matchingLint,
}
}
export const formatTableRowsToSQL = (table: SupaTable, rows: any[]) => {
if (rows.length === 0) return ''
const columns = table.columns.map((col) => `"${col.name}"`).join(', ')
const valuesSets = rows
.map((row) => {
const filteredRow = { ...row }
if ('idx' in filteredRow) delete filteredRow.idx
const values = Object.entries(filteredRow).map(([key, val]) => {
const { dataType, format } = table.columns.find((col) => col.name === key) ?? {}
// We only check for NULL, array and JSON types, everything else we stringify
// given that Postgres can implicitly cast the right type based on the column type
// For string types, we need to deal with escaping single quotes
const stringFormats = ['text', 'varchar']
if (val === null) {
return 'null'
} else if (dataType === 'ARRAY') {
return `'${JSON.stringify(val).replace('[', '{').replace(/.$/, '}')}'`
} else if (format?.includes('json')) {
return `${JSON.stringify(val).replace(/\\"/g, '"').replace(/'/g, "''").replace('"', "'").replace(/.$/, "'")}`
} else if (
typeof format === 'string' &&
typeof val === 'string' &&
stringFormats.includes(format)
) {
return `'${val.replaceAll("'", "''")}'`
} else {
return `'${val}'`
}
})
return `(${values.join(', ')})`
})
.join(', ')
return `INSERT INTO "${table.schema}"."${table.name}" (${columns}) VALUES ${valuesSets};`
}