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>
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import { PG_META_URL } from 'lib/constants/index'
|
|
import { constructHeaders } from '../apiHelpers'
|
|
import { PgMetaDatabaseError, databaseErrorSchema, WrappedResult } from './types'
|
|
import { assertSelfHosted, encryptString, getConnectionString } from './util'
|
|
|
|
export type QueryOptions = {
|
|
query: string
|
|
parameters?: unknown[]
|
|
readOnly?: boolean
|
|
headers?: HeadersInit
|
|
}
|
|
|
|
/**
|
|
* Executes a SQL query against the self-hosted Postgres instance via pg-meta service.
|
|
*
|
|
* _Only call this from server-side self-hosted code._
|
|
*/
|
|
export async function executeQuery<T = unknown>({
|
|
query,
|
|
parameters,
|
|
readOnly = false,
|
|
headers,
|
|
}: QueryOptions): Promise<WrappedResult<T[]>> {
|
|
assertSelfHosted()
|
|
|
|
const connectionString = getConnectionString({ readOnly })
|
|
const connectionStringEncrypted = encryptString(connectionString)
|
|
|
|
const requestBody: { query: string; parameters?: unknown[] } = { query }
|
|
if (parameters !== undefined) {
|
|
requestBody.parameters = parameters
|
|
}
|
|
|
|
const response = await fetch(`${PG_META_URL}/query`, {
|
|
method: 'POST',
|
|
headers: constructHeaders({
|
|
...headers,
|
|
'Content-Type': 'application/json',
|
|
'x-connection-encrypted': connectionStringEncrypted,
|
|
}),
|
|
body: JSON.stringify(requestBody),
|
|
})
|
|
|
|
try {
|
|
const result = await response.json()
|
|
|
|
if (!response.ok) {
|
|
const { message, code, formattedError } = databaseErrorSchema.parse(result)
|
|
const error = new PgMetaDatabaseError(message, code, response.status, formattedError)
|
|
return { data: undefined, error }
|
|
}
|
|
|
|
return { data: result, error: undefined }
|
|
} catch (error) {
|
|
if (error instanceof Error) {
|
|
return { data: undefined, error }
|
|
}
|
|
throw error
|
|
}
|
|
}
|