Registry / database / clickhouse-sql-client

clickhouse-sql-client

JSON →
library1.0.5jsnpmunverified

A lightweight, TypeScript-based SQL query builder for ClickHouse. Version 1.0.5 provides a fluent API to construct SELECT, INSERT, UPDATE, and DELETE queries with ClickHouse-specific features like PREWHERE, LIMIT BY, and raw expressions. It simplifies generating complex SQL strings without runtime dependencies, supporting subqueries, aggregations, and clickhouse-specific functions. Ideal for Node.js applications needing a type-safe query builder with full ClickHouse dialect support. Maintained on GitHub with sparse updates.

npm install clickhouse-sql-client
INSTALL
IMPORT
SIG · CLICKHOUSE-SQL-CLI
C
clickhouse-sql-client
databasejavascriptv1.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ClickhouseQueryBuilder
✓ import { ClickhouseQueryBuilder } from 'clickhouse-sql-client'
✗ const ClickhouseQueryBuilder = require('clickhouse-sql-client')
ESM-only; CommonJS require is not supported.
QueryBuilder
✓ import { QueryBuilder } from 'clickhouse-sql-client'
✗ import { QueryBuilder } from 'clickhouse-sql-client/build/main'
TypeScript types are exported; no separate type import needed.
SelectBuilder
✓ import type { SelectBuilder } from 'clickhouse-sql-client'
✗ import { SelectBuilder } from 'clickhouse-sql-client'
SelectBuilder is used as a parameter type; prefer type import.

Builds a SELECT query with aggregation, filtering, grouping, ordering, and limit using the query builder pattern.

import { ClickhouseQueryBuilder } from 'clickhouse-sql-client'; const dialect = new ClickhouseQueryBuilder(); const query = dialect .select(b => b.raw('count(*) as cnt')) .from(b => b.table.name('events')) .where(b => b.and('event_type', '=', 'click')) .groupBy('event_date') .orderBy('cnt DESC') .limit(10) .sql(); console.log(query); // SELECT count(*) as cnt FROM events WHERE event_type = 'click' GROUP BY event_date ORDER BY cnt DESC LIMIT 10
Debug
Known issues
gotchaString values in where conditions are not automatically quoted; use raw for expressions.
fix
Use b.raw("date = toDateTime('2021-01-01')") instead of b.and('date', '=', 'toDateTime(...)')
affects: *
gotchaLIMIT BY syntax uses string like '1,2 BY id' – builder does not validate or escape.
fix
Ensure the string is safe; consider using limit(5) without BY for simple cases.
affects: *
gotchaINSERT, UPDATE, DELETE are not documented; only SELECT builder is shown in README.
fix
Check source code or tests for other query types, or use raw SQL for mutations.
affects: *
Errors
Common errors & fixes
TypeError: ClickhouseQueryBuilder is not a constructor
Using CommonJS require instead of ESM import.
fix
Use import { ClickhouseQueryBuilder } from 'clickhouse-sql-client'
Cannot find module 'clickhouse-sql-client'
Package not installed or typo in package name.
fix
Run npm install clickhouse-sql-client
Property 'sql' does not exist on type 'QueryBuilder'
Forgetting to call .sql() after building the query.
fix
Chain .sql() at the end of the builder call.
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
clickhouse-sql-client — npm install clickhouse-sql-client · libregistry