Clickhouse js node coding

From ClickHouse/agent-skills · View interactive version

Clickhouse js node coding is an AI agent skill from the GitHub repository ClickHouse/agent-skills. Write idiomatic application code with the ClickHouse Node.js client (`@clickhouse/client`). Use this skill whenever a user is *building* against the Node.js client — configuring the client, pinging, inserting rows in JSON or raw formats, selecting and parsing results, binding query parameters, manag

How to use this skill

Skill file

ClickHouse Node.js Client — Coding

Reference: https://clickhouse.com/docs/integrations/javascript

⚠️ Node.js runtime only. This skill covers the @clickhouse/client

package running in a Node.js runtime exclusively — including **Next.js

Node runtime** API routes, React Server Components, Server Actions, and

standard Node.js processes. Do not apply this skill to browser client

components, Web Workers, Next.js Edge runtime, Cloudflare Workers, or

any usage of @clickhouse/client-web. For browser/edge environments, the

correct package is @clickhouse/client-web.


How to Use This Skill

  1. Match the user's intent to a row in the Task Index below and read the

corresponding reference file before writing code. After reading it, scan any

Answer checklist in that reference and make sure the final answer covers

each relevant item; those checklists capture details users usually need but

are easy to omit in short answers.

  1. Always import from @clickhouse/client (never @clickhouse/client-web)

and create a client with createClient({ url }) or rely on

supported defaults when appropriate. Close it with await client.close()

preferably when it's no longer needed or during graceful shutdown for global resources.

  1. Prefer JSONEachRow for typical row inserts/selects unless the user

has already chosen another format or is streaming raw bytes (CSV / TSV /

Parquet — see examples/node/performance/).

Note on clickhouse_settings: settings passed to createClient are

defaults for every request; they can be overridden per-call by passing

clickhouse_settings directly to insert(), query(), or command().

Always mention this when the user configures settings at the client level.

  1. Always use query_params for user-supplied values — never template-

literal-interpolate them into SQL. See reference/query-parameters.md.

**When answering a parameter-binding question, your response must

explicitly name template-literal interpolation as a "SQL injection

risk"** — even when the user only asked about syntax and did not raise

security. The literal phrase "SQL injection" needs to appear; this is

the most common mistake from PostgreSQL/MySQL users and the security

framing is part of the correct answer, not an optional aside.

  1. Pick the right method for the job:

rows that return data.

(CREATE, DROP, TRUNCATE, ALTER, SET in a session, etc.).

statement (rare in coding scenarios).

throws on connection failure.

  1. Note version constraints when relevant. Examples:

24.5 / 24.8 (no longer experimental since 25.3).


Task Index

Identify the user's task and read the matching reference file.

| Task | Triggers / symptoms | Reference file |

| -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- |

| Configure / connect the client | Building a createClient call, URL parameters, clickhouse_settings, default format, custom HTTP headers | reference/client-configuration.md |

| Compress requests / responses | compression, gzip vs zstd, { codec } option shape, Node version requirements, web limitations | reference/compression.md |

| Ping the server | Health checks, readiness probes, "is ClickHouse up?" | reference/ping.md |

| Choose an insert format | "Which format should I use to insert?", JSON vs raw, JSONEachRow vs JSON vs JSONObjectEachRow | reference/insert-formats.md |

| Insert into a subset of columns / different database | insert({ columns }), excluding columns, ephemeral columns, cross-DB inserts | reference/insert-columns.md |

| Insert values, expressions, dates, decimals | INSERT … VALUES with SQL functions, Date/DateTime from JS, Decimal precision, INSERT … SELECT; inserting a UUID into a UInt128 column is tricky — use when the user is writing code that stores a UUID as UInt128 | reference/insert-values.md |

| Async inserts (server-side batching) | async_insert=1, fire-and-forget vs wait-for-ack | reference/async-insert.md |

| Select and parse results | JSONEachRow reads, JSON with metadata, picking a select format | reference/select-formats.md |

| Parameterize queries | Binding values, special characters / escaping, "SQL injection?", {name: Type} syntax | reference/query-parameters.md |

| Sessions & temporary tables | session_id, CREATE TEMPORARY TABLE, per-session SET commands | reference/sessions.md |

| Modern data types | Dynamic, Variant, JSON (object), Time, Time64, QBit (vector search) | reference/data-types.md |

| Custom JSON parse/stringify | Plug in JSONBig / safe-stable-stringify / a BigInt-aware serializer | reference/custom-json.md |


Conventions used in answers

Web).

long-running services, close on graceful shutdown.

user's scenario requires otherwise.

small / medium result sets; for bigger results suggest streaming.

syntax — never $1, ?, or :name.

clickhouse_settings: { wait_end_of_query: 1 } on the command() call so

the server only acknowledges after the change is applied. See

https://clickhouse.com/docs/en/interfaces/http/#response-buffering.


Out of scope

This skill covers day-to-day coding against @clickhouse/client (Node).

The following topics are intentionally not covered here:

socket hang-ups, ECONNRESET** → use the

clickhouse-js-node-troubleshooting skill.

streaming, async-insert throughput tuning** — see

CODE0.

CODE0.

replication / sharding choices** — see

CODE0.

@clickhouse/client-web and see

CODE0.


Still Stuck?

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.