@repo/clickhouse package provides a ClickHouse client wrapper for recording and querying uptime metrics.
Overview
This package exports:recordUptimeEvent()- Record a single uptime checkrecordUptimeEvents()- Batch record multiple checksgetRecentStatusEvents()- Query recent status eventsgetStatusEventsForLookbackHours()- Query historical eventsgetClickhouseClient()- Get the underlying ClickHouse client
Configuration
Required environment variables:packages/clickhouse/README.md.
Table Schema
The package automatically creates the table if it doesn’t exist:packages/clickhouse/src/index.ts
Recording Events
Single Event
Batch Events
From the worker app:apps/worker/src/index.ts
packages/clickhouse/src/index.ts
Querying Events
Recent Events (Per-Check Mode)
Get the most recent N checks per website:Historical Events (Per-Day Mode)
Get all events within a time window:packages/api/src/routes/website.ts
Types
UptimeEventRecord
packages/clickhouse/src/index.ts
UptimeStatus
packages/clickhouse/src/index.ts
StatusEventRow
packages/clickhouse/src/index.ts
Timeout Protection
All operations have configurable timeouts:packages/clickhouse/src/index.ts
Schema Management
The package automatically ensures the schema exists before operations:packages/clickhouse/src/index.ts
packages/clickhouse/src/index.ts
Error Handling
The package handles errors gracefully and returns empty arrays on failure:packages/clickhouse/src/index.ts
Location
packages/clickhouse/src/index.ts