[hypequery](https://hypequery.com/) › ClickHouse JS: JavaScript & TypeScript Query Builder | hypequery
Index for agents: https://hypequery.com/llms.txt
Canonical page: https://hypequery.com/clickhouse-js

> Use ClickHouse from JavaScript without living on raw query strings, hand-written row types, and repeated response parsing.

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

ClickHouse JS

# The JavaScript query builder built for ClickHouse

The raw ClickHouse client gets rows back. hypequery keeps that connection and adds schema-generated types and composable query code, so the rest of your app isn't built on casts and copied SQL.

[Start with hypequery ](https://hypequery.com/docs/quick-start)[Compare vs @clickhouse/client](https://hypequery.com/compare/hypequery-vs-clickhouse-client)

Language

JavaScript & TypeScript

Type source

Generated from schema

Best for

Analytics-heavy JS apps

## The raw client stops at query execution

It connects to ClickHouse and runs SQL well. The problem starts after that, when every caller has to decide what the rows look like and how much parsing or casting it wants to do.

## JavaScript callers keep re-solving the same runtime type issues

DateTime, UInt64, Nullable, and Decimal do not map the way many teams expect. Without a shared type source, every query callsite ends up making its own assumptions.

## The same query logic leaks into every runtime

A JavaScript stack often spans scripts, server code, and UI consumers. If the query only exists as a string plus an informal row shape, reuse turns into copy-paste very quickly.

What changes

## Keep the JavaScript runtime, replace the fragile query layer

You keep your existing stack. Generate a schema file from ClickHouse and use it as the basis for query code, so JavaScript callers stop inventing row types ad hoc.

- Schema types generated from your live ClickHouse database
- Correct JS runtime type mappings (DateTime→string, UInt64→string, Nullable→T|null)
- Composable builder with filters, groupBy, orderBy, and aggregations
- Composable builder plus raw SQL escape hatches for ClickHouse-specific clauses
- Works across Node.js, Next.js, Bun, and other JavaScript runtimes

Before vs after

### From raw client rows to schema-aware query results

what-changes.ts

```
// @clickhouse/client — what most teams start with
const result = await client.query({
  query: `SELECT order_date, sum(total) as revenue
          FROM orders
          WHERE tenant_id = {tenant_id: String}
          GROUP BY order_date`,
  query_params: { tenant_id: ctx.tenantId },
});

const rows = await result.json();
// rows: { data: any[] } — no types, no safety

// ---

// hypequery — generated from your ClickHouse schema
const rows = await db
  .table('orders')
  .select(['order_date', 'revenue'])
  .where('tenant_id', 'eq', ctx.tenantId)
  .groupBy('order_date')
  .orderBy('order_date', 'DESC')
  .execute();

// rows: { order_date: string; revenue: string }[]
// correct ClickHouse-to-JS type mappings, always
```

The second version has a real type source. The first leaves every caller to cast the result however it likes.

When a query becomes shared

## Move useful queries into named definitions

Once a JavaScript query stops being local implementation detail, it should stop living as an unstructured string. Promote it into a named definition and let the rest of the stack consume that definition instead.

That is the practical difference between this page and the raw-client story. The client gives you transport. The named query layer gives you something the rest of the product can safely call.

If you are evaluating the tradeoffs, the comparison page spells out where @clickhouse/client stays the simpler option and where it starts leaving too much work to application code.

Named query

### A reusable query definition instead of another raw string

when-a-query-becomes-shared.ts

```
import { initServe } from '@hypequery/serve';
import { z } from 'zod';

const { query, serve } = initServe({
  context: () => ({ db }),
});

const revenueByDay = query({
  input: z.object({
    tenantId: z.string(),
    startDate: z.string(),
    endDate: z.string(),
  }),
  query: ({ ctx, input }) =>
    ctx.db
      .table('orders')
      .where('tenant_id', 'eq', input.tenantId)
      .where('order_date', 'gte', input.startDate)
      .where('order_date', 'lte', input.endDate)
      .groupBy(['order_date'])
      .sum('total', 'revenue')
      .execute(),
});

export const api = serve({
  queries: { revenueByDay },
});
```

This is the step that makes the JavaScript story scale. The query stops being “whatever this file does” and becomes something the rest of the app can depend on.

Where teams usually get stuck

## Questions teams ask

### What this page is really comparing

It is less about official client versus unofficial client, and more about whether query code stays raw and local or becomes typed and reusable.

### Where JavaScript teams usually get stuck

Usually not on connecting to ClickHouse. Usually on keeping row shapes, response parsing, and copied SQL under control once the codebase grows a few consumers.

### Why the type source matters

If the query layer starts from the wrong assumptions about DateTime or UInt64, every higher-level abstraction inherits the mistake.

### Where to branch next

Use the Node.js page for server and job concerns, Next.js for App Router concerns, and React for browser consumption.

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/async-inserts-node)

### [ClickHouse async inserts from Node.js: per-row vs batch vs async_insert](https://hypequery.com/recipes/async-inserts-node)

[Insert the same 1,000 rows from Node per row, in client batches and with async_insert, and count the parts each creates: 1,000, 4, 10 and 1.](https://hypequery.com/recipes/async-inserts-node)

[Node.jsClickHouseIngestionReal time analytics](https://hypequery.com/recipes/async-inserts-node)

[Open recipe](https://hypequery.com/recipes/async-inserts-node)

[Guide · ClickHouse 25.8](https://hypequery.com/guides/clickhouse-docker-compose)

### [ClickHouse with Docker Compose: a pinned, persistent local server with a million-row sample dataset](https://hypequery.com/guides/clickhouse-docker-compose)

[Run ClickHouse 25.8 in Docker Compose with a healthcheck, a password, volumes and a 1M-row sample dataset, then connect from Node, Python and hypequery.](https://hypequery.com/guides/clickhouse-docker-compose)

[Quantile](https://hypequery.com/guides/clickhouse-docker-compose)

[Open guide](https://hypequery.com/guides/clickhouse-docker-compose)

Further reading

## Go deeper where it actually helps

### [hypequery vs @clickhouse/client](https://hypequery.com/compare/hypequery-vs-clickhouse-client)

[What you actually gain when you move from raw queries to generated types and a reusable JS analytics layer.](https://hypequery.com/compare/hypequery-vs-clickhouse-client)

[Open guide](https://hypequery.com/compare/hypequery-vs-clickhouse-client)

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

[Every realistic JavaScript and TypeScript option in 2026, with honest tradeoffs on each.](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 in JavaScript and how to fix it.](https://hypequery.com/blog/clickhouse-typescript-type-problem)

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

### [hypequery vs Kysely](https://hypequery.com/compare/hypequery-vs-kysely)

[Where Kysely is excellent, where ClickHouse changes the tradeoffs, and when hypequery is the better fit.](https://hypequery.com/compare/hypequery-vs-kysely)

[Open guide](https://hypequery.com/compare/hypequery-vs-kysely)

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 React](https://hypequery.com/clickhouse-react)[ClickHouse Next.js](https://hypequery.com/clickhouse-nextjs)

Next step

## Replace one raw query in a JavaScript runtime you already own

Pick a query that currently returns untyped rows, generate the schema, and move that query onto the builder. That one query is enough to tell whether generated types save you work.

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)
