ruvector/studio/lib/pg-format.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

77 lines
1.8 KiB
TypeScript

// [Joshen] These are from https://github.com/datalanche/node-pg-format/blob/master/lib/index.js
function formatDate(date: any) {
date = date.replace('T', ' ')
date = date.replace('Z', '+00')
return date
}
function arrayToList(useSpace: any, array: any, formatter: any) {
let sql = ''
sql += useSpace ? ' (' : '('
for (var i = 0; i < array.length; i++) {
sql += (i === 0 ? '' : ', ') + formatter(array[i])
}
sql += ')'
return sql
}
export function quoteLiteral(value: any): any {
let literal = null
let explicitCast = null
if (value === undefined || value === null) {
return 'NULL'
} else if (value === false) {
return "'f'"
} else if (value === true) {
return "'t'"
} else if (value instanceof Date) {
return "'" + formatDate(value.toISOString()) + "'"
} else if (value instanceof Buffer) {
return "E'\\\\x" + value.toString('hex') + "'"
} else if (Array.isArray(value) === true) {
let temp = []
for (let i = 0; i < value.length; i++) {
if (Array.isArray(value[i]) === true) {
temp.push(arrayToList(i !== 0, value[i], quoteLiteral))
} else {
temp.push(quoteLiteral(value[i]))
}
}
return temp.toString()
} else if (value === Object(value)) {
explicitCast = 'jsonb'
literal = JSON.stringify(value)
} else {
literal = value.toString().slice(0) // create copy
}
let hasBackslash = false
let quoted = "'"
for (let i = 0; i < literal.length; i++) {
let c = literal[i]
if (c === "'") {
quoted += c + c
} else if (c === '\\') {
quoted += c + c
hasBackslash = true
} else {
quoted += c
}
}
quoted += "'"
if (hasBackslash === true) {
quoted = 'E' + quoted
}
if (explicitCast) {
quoted += '::' + explicitCast
}
return quoted
}