ClickHouse from TypeScript: TypeORM, Prisma, and what actually works
You've got a TypeScript backend on TypeORM or Prisma. You've added ClickHouse for analytics. The obvious next step is to point your ORM at it. The short answer: you can't, and you shouldn't want to. Neither TypeORM nor Prisma ships a ClickHouse driver. Even if one did, an ORM's model of the world is the wrong fit for an analytical database. Here's why, and what TypeScript teams actually use…
When using TypeScript with ClickHouse for analytics, you'll find that neither TypeORM nor Prisma provide a ClickHouse driver. These ORMs are not designed to work with analytical databases like ClickHouse. Instead, a better approach is to employ a separate ClickHouse-native layer for analytics alongside your ORM for transactional data.
The official ClickHouse client, @clickhouse/client, written in TypeScript, can be used for a handful of queries. It's fast and supports parameterized queries, but there are some limitations. The result types are not inferred by TypeScript, which can lead to issues if the schema changes.
For more complex analytics needs, a typed query builder like hypequery can be a better fit. hypequery generates types from your actual ClickHouse schema, providing compile-time type safety. It wraps the official client and can be used in both Node and browser/edge runtimes. It offers additional features like metric definitions, validated HTTP APIs, typed React hooks, and multi-tenant scoping.
When connecting to ClickHouse Cloud from TypeScript, remember to use the HTTPS endpoint, watch for slow waking up services, and use a read-only user for your API path. Also, be aware that 64-bit numbers arrive as strings in JSON format and may lose precision if converted with Number().
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.