[hypequery](https://hypequery.com/) › ClickHouse Schema to TypeScript Types | hypequery
Index for agents: https://hypequery.com/llms.txt
Canonical page: https://hypequery.com/clickhouse-schema

> Generate TypeScript types from your live ClickHouse schema so query code stops relying on hand-written interfaces and incorrect runtime assumptions.

[Open sourceApache 2.0](https://github.com/hypequery/hypequery)

ClickHouse Schema

# Generate TypeScript types from your live ClickHouse schema

The first problem most TypeScript teams hit on ClickHouse is a type mismatch. The database returns one thing, their interfaces claim another, and the compiler happily trusts the wrong version. hypequery fixes that at the schema boundary.

[Start with hypequery ](https://hypequery.com/docs/quick-start)[Read the schemas guide](https://hypequery.com/docs/schemas)

Command

npx @hypequery/cli generate

Type source

Live ClickHouse database

Update strategy

Re-run after schema changes

## ClickHouse runtime types are easy to misread

DateTime is not a JavaScript Date. UInt64 is often not a safe number. Nullable columns change the shape again. If you guess these mappings in an interface, the compiler cannot tell you that the guess is wrong.

## Manual interfaces become stale immediately

A renamed column or changed type means updating interfaces by hand, then hoping every cast and helper stayed aligned. That is fragile even on a small team.

## Raw clients push the typing problem downstream

If the client gives you `any[]`, somebody still has to decide what the rows look like. That usually ends in a cast, which leaves the boundary between the database and your code unchecked.

What generate actually does

## Read the live schema and write the TypeScript file you would not maintain by hand

The `generate` command introspects the live ClickHouse schema and writes a database interface you can import everywhere else. From then on, your query code starts from the column types the database itself reports.

- Reads schema from your live ClickHouse information_schema
- Correct mappings: DateTime→string, UInt64→string, Nullable(T)→T|null, Decimal→string
- Outputs a typed DB interface for every table in the target database
- Re-run after any schema change to keep types in sync
- Works with ClickHouse Cloud, self-hosted, and local instances

Generate command

### Point the CLI at the real database

what-generate-actually-does.ts

```
# introspect your live ClickHouse schema and generate TypeScript types
npx @hypequery/cli generate \
  --host your-clickhouse-host \
  --port 8123 \
  --database analytics \
  --output ./src/schema.ts
```

This is the only manual step. After that, the generated file becomes the type source for the query builder and the rest of the TypeScript layer.

What you get back

## A schema file that reflects runtime reality

The generated output becomes boring infrastructure. You import it once, build queries against it, and let TypeScript flag the places that no longer match after a schema change.

The mappings follow ClickHouse runtime behavior rather than wishful TypeScript shapes. That is why `UInt64` stays a string and why `DateTime` does not become `Date` automatically.

Once this file exists, the rest of the tooling gets simpler. Autocomplete improves, casts disappear, and query edits stop feeling like blind string manipulation.

Generated schema

### The kind of file you import everywhere else

what-you-get-back.ts

```
// generated schema.ts — always reflects your live ClickHouse schema

export interface DB {
  orders: {
    id: string; // UUID → string
    total: string; // Decimal(18,4) → string (preserves precision)
    created_at: string; // DateTime → string (ClickHouse format)
    tenant_id: string; // String
    status: string; // LowCardinality(String) → string
    user_id: string | null; // Nullable(String) → string | null
    quantity: number; // UInt32 → number
    amount: string; // UInt64 → string (avoids JS precision loss)
  };
  events: {
    event_name: string;
    occurred_at: string;
    properties: string; // JSON → string
    session_id: string | null;
  };
}
```

This file is a database-shaped interface that matches what ClickHouse actually returns.

Where teams usually get stuck

## Questions teams ask

### How do I show a ClickHouse table schema?

DESCRIBE TABLE events lists each column with its type, default and comment; SHOW CREATE TABLE events prints the full DDL, including the engine and ORDER BY; system.columns has the same column data for every table. To turn that schema into TypeScript types, run npx hypequery generate against the same database.

### Why this matters more than nicer query syntax

If the schema types are wrong, every nicer abstraction above them is built on sand. Fixing the type source is usually a better first move than introducing more wrappers.

### What teams usually automate next

Most teams rerun generation after schema changes or in CI so type drift gets caught before application code is merged.

### What this page is not about

This page covers one narrow piece: keeping runtime ClickHouse shapes and TypeScript expectations aligned. It does not cover migrations or ORMs.

### Where to go after this

Once the schema file exists, the next pages that matter are the query builder and TypeScript workflow pages. That is where the generated types start paying off in everyday code.

Examples

## Recipes and guides you can run against a seeded ClickHouse

Every example runs against the same seeded ClickHouse dataset. Scaffold one with `npx @hypequery/cli create <slug> -y`, or browse the [full list](https://hypequery.com/examples).

[Recipe · TypeScript](https://hypequery.com/recipes/projection-for-dataset-queries)

### [Add a ClickHouse projection that a typed dataset query uses automatically](https://hypequery.com/recipes/projection-for-dataset-queries)

[Add a sort-key and an aggregate projection to a ClickHouse table, then prove with EXPLAIN and query_log that an unchanged dataset query reads from them.](https://hypequery.com/recipes/projection-for-dataset-queries)

[Node.jsClickHousePerformanceTime series](https://hypequery.com/recipes/projection-for-dataset-queries)

[Open recipe](https://hypequery.com/recipes/projection-for-dataset-queries)

[Recipe · TypeScript](https://hypequery.com/recipes/replacingmergetree-upserts)

### [Upserts and deletes in ClickHouse with ReplacingMergeTree and a typed dataset](https://hypequery.com/recipes/replacingmergetree-upserts)

[Upsert and delete rows with ReplacingMergeTree, read the latest version with FINAL or argMax, and pin the results before and after OPTIMIZE.](https://hypequery.com/recipes/replacingmergetree-upserts)

[Node.jsClickHouseSaaS analyticsData modeling](https://hypequery.com/recipes/replacingmergetree-upserts)

[Open recipe](https://hypequery.com/recipes/replacingmergetree-upserts)

[Recipe · TypeScript](https://hypequery.com/recipes/ttl-data-retention)

### [Per-plan data retention in ClickHouse with TTL and a typed dataset](https://hypequery.com/recipes/ttl-data-retention)

[Expire free-plan events after 30 days and starter events after 180 with TTL WHERE, clear a column with column TTL, and pin the result on any run date.](https://hypequery.com/recipes/ttl-data-retention)

[Node.jsClickHouseSaaS analyticsMulti-tenant](https://hypequery.com/recipes/ttl-data-retention)

[Open recipe](https://hypequery.com/recipes/ttl-data-retention)

Further reading

## Go deeper where it actually helps

### [Schemas guide](https://hypequery.com/docs/schemas)

[The full reference for schema generation, covering options, configuration, and the complete type mapping table.](https://hypequery.com/docs/schemas)

[Open guide](https://hypequery.com/docs/schemas)

### [ClickHouse Query Builder](https://hypequery.com/clickhouse-query-builder)

[How the generated schema types power the composable query builder.](https://hypequery.com/clickhouse-query-builder)

[Open guide](https://hypequery.com/clickhouse-query-builder)

### [The ClickHouse TypeScript type problem](https://hypequery.com/blog/clickhouse-typescript-type-problem)

[Why DateTime, UInt64, Nullable, and Decimal return the wrong types and how schema generation fixes it.](https://hypequery.com/blog/clickhouse-typescript-type-problem)

[Open guide](https://hypequery.com/blog/clickhouse-typescript-type-problem)

Related pillars

[ClickHouse with TypeScript and Python](https://hypequery.com/clickhouse)[ClickHouse TypeScript](https://hypequery.com/clickhouse-typescript)[ClickHouse Query Builder](https://hypequery.com/clickhouse-query-builder)[ClickHouse ORM](https://hypequery.com/clickhouse-orm)[ClickHouse schema design for app developers](https://hypequery.com/blog/clickhouse-schema-design-for-application-developers)

Next step

## Run generate against a real ClickHouse database

Do it on the schema you already have, then inspect the generated file. You will know quickly whether it removes the casts and wrong assumptions your current code relies on.

Open source, and it runs in your own backend. Want it hosted?

[Start with hypequery ](https://hypequery.com/docs/quick-start)[Read the schemas guide](https://hypequery.com/docs/schemas)
