Runtime Controls
Configure retries, warnings, read replicas, telemetry, and safety limits.
Runtime Controls
Problem: defaults are fine for local development, but production needs guardrails.
Solution: pass a config object to connect().
Production config starter
import { connect, KadakMetrics } from '@shyk/kadak-orm'
const metrics = new KadakMetrics()
const db = connect({
url: 'postgres://postgres:postgres@localhost:5432/kadak_demo',
readReplicas: ['postgres://postgres:postgres@localhost:5433/kadak_demo'],
warnings: 'relaxed',
retryAttempts: 2,
retryDelayMs: 200,
retryWrites: false,
defaultLimit: 100,
validateResults: true,
slowQueryMs: 250,
largeResultRows: 1000,
repeatedQueryThreshold: 25,
explainAnalyze: true,
explainThresholdMs: 300,
metrics,
onQuery: (event) => {
if (event.durationMs > 300) console.log('slow query', event.sql)
},
}, { users })What each control solves
readReplicas: routeSELECTtraffic to replicas.defaultLimit: prevent accidental huge list responses.warnings: 'strict': fail fast on risky queries.retryAttempts: recover from short network failures.validateResults: verify DB result shape against schema.explainAnalyze: inspect slow selects and warn for sequential scans.
Important: keep
retryWrites: falseunless your writes are idempotent.
Metrics
console.log(metrics.snapshot())
console.log(metrics.exportPrometheus())API version
import { KADAK_API_VERSION } from '@shyk/kadak-orm'
console.log(KADAK_API_VERSION)