Skip to Content
Getting started

Core concepts

Datasets, serving, and clients in hypequery, and where the TypeScript query builder fits.

hypequery has three concepts, and they work the same way in TypeScript and Python:

  • datasets: the semantic layer, where analytics meaning is defined once
  • serving: authenticated HTTP endpoints for those datasets, when another consumer needs them
  • clients: typed React hooks and the MCP server, which query the served endpoints

TypeScript also ships a type-safe ClickHouse query builder for queries that only live in one place.

ConceptUse it whenTypeScriptPython
DatasetsThe same dimensions and measures are used in more than one place@hypequery/datasetshypequery.datasets
ServingA frontend, service, or agent needs the datasets over HTTP@hypequery/servehypequery.serve
ClientsA React dashboard or an AI agent consumes them@hypequery/react, @hypequery/mcpthe same packages, against a Python API
Query builderA query is local to one place@hypequery/clickhousenot available

1. Datasets (semantic layer)

Datasets turn table semantics into reusable analytics definitions. This is where you define:

  • dimensions such as country, status, and created_at
  • measures such as user counts and revenue
  • shared filters, tenant keys, and time keys

A dataset describes a source table, and a dataset client runs semantic queries against that definition: you ask for dimensions and measures by name, and hypequery writes the ClickHouse SQL.

import {
  createDatasetClient,
  dataset,
  dimension,
  eq,
  measure,
} from '@hypequery/datasets';
import { createQueryBuilder } from '@hypequery/clickhouse';

const db = createQueryBuilder({
  url: process.env.CLICKHOUSE_URL!,
  username: process.env.CLICKHOUSE_USER!,
  password: process.env.CLICKHOUSE_PASSWORD!,
  database: process.env.CLICKHOUSE_DATABASE!,
});

const analytics = createDatasetClient({ queryBuilder: db });

export const Users = dataset('users', {
  source: 'users',
  timeKey: 'created_at',
  dimensions: {
    id: dimension.string(),
    email: dimension.string(),
    status: dimension.string(),
    createdAt: dimension.timestamp({ column: 'created_at' }),
  },
  measures: {
    userCount: measure.count('id'),
    activeUserCount: measure.count('id', {
      filters: [eq('status', 'active')],
    }),
  },
});

const result = await analytics.execute(Users, {
  dimensions: ['status'],
  measures: ['userCount', 'activeUserCount'],
  limit: 10,
});

The same semantics can now be reused across APIs, dashboards, background jobs, notebooks, and agent-facing tools without rewriting SQL.

2. Serving (optional)

Serving is a delivery layer for datasets. Add it when you need:

  • HTTP routes for a frontend, a mobile app, or another service
  • validation, authentication, and tenant scoping on every request
  • generated OpenAPI documents
  • an endpoint for React hooks or the MCP server
import { initServe } from '@hypequery/serve';
import { db } from './client';
import { Users } from './datasets/users';

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

export const api = serve({
  datasets: { users: Users },
  queryBuilder: db,
});

Serving does not introduce a new query language. It exposes the same dataset definitions through an application surface, mounted in the framework you already run.

3. Clients

Typed React hooks query served datasets from a dashboard, and the MCP server exposes them to AI agents as bounded tools. Both query the same endpoints whether the API is written in TypeScript or Python; only how the hooks get their types differs. A TypeScript app infers them from the API, and a Python API exports a client contract that hypequery generate:client turns into types (React: choose how your hooks get their types).

The query builder (TypeScript)

The TypeScript SDK also includes a type-safe ClickHouse query builder. Use it for queries that live in one place, where a dataset would be more structure than you need:

import { createQueryBuilder } from '@hypequery/clickhouse';
import type { IntrospectedSchema } from './generated-schema';

const db = createQueryBuilder<IntrospectedSchema>({
  url: process.env.CLICKHOUSE_URL!,
  username: process.env.CLICKHOUSE_USER!,
  password: process.env.CLICKHOUSE_PASSWORD!,
  database: process.env.CLICKHOUSE_DATABASE!,
});

const latestUsers = await db
  .table('users')
  .select(['id', 'email', 'created_at'])
  .where('status', 'eq', 'active')
  .orderBy('created_at', 'DESC')
  .limit(10)
  .execute();

One example, three stages

Stage 1 — local query

const activeUsers = await db
  .table('users')
  .select(['id', 'created_at'])
  .where('status', 'eq', 'active')
  .execute();

Stage 2 — dataset

import { dataset, dimension, eq, measure } from '@hypequery/datasets';

export const Users = dataset('users', {
  source: 'users',
  timeKey: 'created_at',
  dimensions: {
    id: dimension.string(),
    createdAt: dimension.timestamp({ column: 'created_at' }),
  },
  measures: {
    activeUsers: measure.count('id', {
      filters: [eq('status', 'active')],
    }),
  },
});

Stage 3 — runtime

export const api = serve({
  datasets: { users: Users },
  queryBuilder: db,
});

You can also expose hand-authored builder queries through the same runtime:

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

const latestActiveUsers = query({
  query: ({ ctx }) =>
    ctx.db
      .table('users')
      .select(['id', 'email', 'created_at'])
      .where('status', 'eq', 'active')
      .orderBy('created_at', 'DESC')
      .limit(10)
      .execute(),
});

export const api = serve({
  queries: { latestActiveUsers },
  datasets: { users: Users },
  queryBuilder: db,
});

When to move between layers

Define a dataset when:

  • the same dimensions, measures, or filters appear in more than one place
  • metrics need a single definition
  • queries must be scoped to a tenant

Add serving when:

  • datasets should be reachable over HTTP
  • you need validation or auth
  • a React dashboard or an AI agent needs them

In TypeScript, if a query only lives in one place, the query builder on its own is often enough.

On this page

Get early access to hypequery cloud.

Cloud hosts the same model you run in your backend, with a managed API and MCP server, versions, and rollback. We're letting teams in a few at a time. Join the waitlist and we'll reach out when your project can go live.

How do you want to build your analytics layer? (Optional)
What features do you most need? (Optional)

Pick as many as you like.

Only your email is required. All other questions are optional.