| name | clickhouse-hello-world |
| description | Create your first ClickHouse table, insert data, and run analytical queries.
Use when starting a new ClickHouse project, learning MergeTree basics,
or testing your ClickHouse connection with real operations.
Trigger: "clickhouse hello world", "first clickhouse table",
"clickhouse quick start", "create clickhouse table", "clickhouse example".
|
| allowed-tools | Read, Write, Edit, Bash(npm:*), Bash(node:*) |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","database","analytics","clickhouse","olap"] |
| compatible-with | claude-code |
ClickHouse Hello World
Overview
Create a MergeTree table, insert rows with JSONEachRow, and run your first
analytical query -- all using the official @clickhouse/client.
Prerequisites
@clickhouse/client installed and connected (see clickhouse-install-auth)
Instructions
Step 1: Create a MergeTree Table
import { createClient } from '@clickhouse/client';
const client = createClient({
url: process.env.CLICKHOUSE_HOST ?? 'http://localhost:8123',
username: process.env.CLICKHOUSE_USER ?? 'default',
password: process.env.CLICKHOUSE_PASSWORD ?? '',
});
await client.command({
query: `
CREATE TABLE IF NOT EXISTS events (
event_id UUID DEFAULT generateUUIDv4(),
event_type LowCardinality(String),
user_id UInt64,
payload String,
created_at DateTime DEFAULT now()
)
ENGINE = MergeTree()
ORDER BY (event_type, created_at)
PARTITION BY toYYYYMM(created_at)
TTL created_at + INTERVAL 90 DAY
`,
});
console.log('Table "events" created.');
Key concepts:
MergeTree() -- the foundational ClickHouse engine for analytics
ORDER BY -- defines the primary index (sort key); pick columns you filter/group on
PARTITION BY -- splits data into parts by month for efficient pruning
TTL -- automatic data expiration
LowCardinality(String) -- dictionary-encoded string, ideal for columns with < 10K distinct values