@hypequery/clickhouse 2.5.3 → 2.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-CLI.md +20 -33
- package/README.md +23 -101
- package/package.json +18 -5
package/README-CLI.md
CHANGED
|
@@ -1,50 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ClickHouse TypeScript schema generator
|
|
2
2
|
|
|
3
|
-
`hypequery-generate-types`
|
|
3
|
+
`hypequery-generate-types` reads a live ClickHouse schema and writes the `IntrospectedSchema` TypeScript interface used by `@hypequery/clickhouse`. Generated types keep table names, column names, nullable values, arrays, dates, and large integers aligned with what ClickHouse returns over HTTP.
|
|
4
4
|
|
|
5
|
-
Most
|
|
5
|
+
Most projects should use the friendlier main CLI:
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
+
npm install -D @hypequery/cli
|
|
8
9
|
npx hypequery generate
|
|
9
10
|
```
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
Use the lower-level binary when you only installed `@hypequery/clickhouse` or want direct control over the output path.
|
|
12
13
|
|
|
13
|
-
##
|
|
14
|
+
## Run it
|
|
14
15
|
|
|
15
16
|
```bash
|
|
16
17
|
npm install @hypequery/clickhouse
|
|
18
|
+
npx hypequery-generate-types ./analytics/schema.ts
|
|
17
19
|
```
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
npx hypequery-generate-types
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
By default it:
|
|
26
|
-
|
|
27
|
-
- reads ClickHouse connection details from environment variables
|
|
28
|
-
- introspects tables in the target database
|
|
29
|
-
- writes `generated-schema.ts` in the current working directory
|
|
21
|
+
With no path, the command writes `generated-schema.ts` in the current directory.
|
|
30
22
|
|
|
31
|
-
|
|
23
|
+
## Connection settings
|
|
32
24
|
|
|
33
|
-
|
|
34
|
-
npx hypequery-generate-types ./src/types/db-schema.ts
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Environment Variables
|
|
38
|
-
|
|
39
|
-
| Variable | Description |
|
|
25
|
+
| Variable | Purpose |
|
|
40
26
|
| --- | --- |
|
|
41
|
-
| `CLICKHOUSE_URL` |
|
|
27
|
+
| `CLICKHOUSE_URL` | ClickHouse HTTP URL |
|
|
42
28
|
| `CLICKHOUSE_HOST` | Deprecated alias for `CLICKHOUSE_URL` |
|
|
43
|
-
| `CLICKHOUSE_USER` |
|
|
44
|
-
| `CLICKHOUSE_PASSWORD` |
|
|
45
|
-
| `CLICKHOUSE_DATABASE` |
|
|
46
|
-
|
|
47
|
-
Example:
|
|
29
|
+
| `CLICKHOUSE_USER` | Username |
|
|
30
|
+
| `CLICKHOUSE_PASSWORD` | Password |
|
|
31
|
+
| `CLICKHOUSE_DATABASE` | Database to introspect |
|
|
48
32
|
|
|
49
33
|
```bash
|
|
50
34
|
CLICKHOUSE_URL=http://localhost:8123 \
|
|
@@ -54,7 +38,7 @@ CLICKHOUSE_DATABASE=analytics \
|
|
|
54
38
|
npx hypequery-generate-types ./analytics/schema.ts
|
|
55
39
|
```
|
|
56
40
|
|
|
57
|
-
##
|
|
41
|
+
## Use the result
|
|
58
42
|
|
|
59
43
|
```ts
|
|
60
44
|
import { createQueryBuilder } from '@hypequery/clickhouse';
|
|
@@ -68,10 +52,13 @@ const db = createQueryBuilder<IntrospectedSchema>({
|
|
|
68
52
|
});
|
|
69
53
|
```
|
|
70
54
|
|
|
71
|
-
|
|
55
|
+
Regenerate after schema changes so TypeScript catches application queries that need updating.
|
|
56
|
+
|
|
57
|
+
## Documentation
|
|
72
58
|
|
|
73
59
|
- [Quick start](https://hypequery.com/docs/quick-start)
|
|
74
|
-
- [
|
|
60
|
+
- [Connection reference](https://hypequery.com/docs/reference/connection)
|
|
61
|
+
- [Query builder](https://hypequery.com/clickhouse-query-builder)
|
|
75
62
|
|
|
76
63
|
## License
|
|
77
64
|
|
package/README.md
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
# @hypequery/clickhouse
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The type-safe ClickHouse query builder for TypeScript.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Generate types from your live ClickHouse schema, write fluent analytics queries, and catch broken table names, columns, joins, filters, and result shapes before production. `@hypequery/clickhouse` keeps the power of ClickHouse without the `any[]`, drifting interfaces, and stringly typed application SQL.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
-
Node:
|
|
10
|
-
|
|
11
9
|
```bash
|
|
12
10
|
npm install @hypequery/clickhouse
|
|
11
|
+
npm install -D @hypequery/cli
|
|
12
|
+
npx hypequery generate
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm install @hypequery/clickhouse @clickhouse/client-web
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
`url` is the preferred connection field. `host` is still supported as a deprecated alias.
|
|
22
|
-
|
|
23
|
-
## Quick Start
|
|
15
|
+
## Your first typed query
|
|
24
16
|
|
|
25
17
|
```ts
|
|
26
18
|
import { createQueryBuilder } from '@hypequery/clickhouse';
|
|
@@ -33,119 +25,49 @@ const db = createQueryBuilder<IntrospectedSchema>({
|
|
|
33
25
|
database: process.env.CLICKHOUSE_DATABASE!,
|
|
34
26
|
});
|
|
35
27
|
|
|
36
|
-
const recentOrders = await db
|
|
37
|
-
.table('orders')
|
|
38
|
-
.select(['id', 'user_id', 'total', 'created_at'])
|
|
39
|
-
.where('created_at', 'gte', '2026-01-01')
|
|
40
|
-
.orderBy('created_at', 'DESC')
|
|
41
|
-
.limit(20)
|
|
42
|
-
.execute();
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## Main Path
|
|
46
|
-
|
|
47
|
-
1. Generate schema types with the CLI
|
|
48
|
-
2. Create a typed `db`
|
|
49
|
-
3. Write and execute queries locally
|
|
50
|
-
4. Promote important queries into `@hypequery/serve` when they need a shared contract or HTTP surface
|
|
51
|
-
|
|
52
|
-
## Common Patterns
|
|
53
|
-
|
|
54
|
-
### Aggregation
|
|
55
|
-
|
|
56
|
-
```ts
|
|
57
28
|
const revenueByRegion = await db
|
|
58
29
|
.table('orders')
|
|
59
30
|
.select(['region'])
|
|
60
|
-
.
|
|
31
|
+
.where('status', 'eq', 'completed')
|
|
32
|
+
.sum('amount', 'revenue')
|
|
61
33
|
.groupBy('region')
|
|
62
34
|
.orderBy('revenue', 'DESC')
|
|
63
35
|
.execute();
|
|
64
36
|
```
|
|
65
37
|
|
|
66
|
-
|
|
38
|
+
The result type is inferred from your real ClickHouse schema and the query itself. Rename a column, regenerate types, and affected queries fail at compile time.
|
|
67
39
|
|
|
68
|
-
|
|
69
|
-
const ordersWithUsers = await db
|
|
70
|
-
.table('orders')
|
|
71
|
-
.innerJoin('users', 'user_id', 'users.id')
|
|
72
|
-
.select(['orders.id', 'users.email', 'orders.total'])
|
|
73
|
-
.where('users.status', 'eq', 'active')
|
|
74
|
-
.execute();
|
|
75
|
-
```
|
|
40
|
+
## ClickHouse-first, not lowest-common-denominator SQL
|
|
76
41
|
|
|
77
|
-
|
|
42
|
+
- native `PREWHERE`, `FINAL`, `LIMIT BY`, array joins, totals, settings, and CTEs;
|
|
43
|
+
- typed joins, filters, groups, ordering, pagination, and streaming;
|
|
44
|
+
- sums, distinct counts, percentiles, `argMax`, `argMin`, standard deviation, and variance;
|
|
45
|
+
- explicit expression helpers for window functions and specialised ClickHouse SQL;
|
|
46
|
+
- correct runtime types for dates, large integers, nullable values, and arrays.
|
|
78
47
|
|
|
79
48
|
```ts
|
|
80
|
-
const
|
|
49
|
+
const topProducts = await db
|
|
81
50
|
.table('products')
|
|
51
|
+
.final()
|
|
82
52
|
.select(['category', 'id', 'score'])
|
|
83
53
|
.orderBy('score', 'DESC')
|
|
84
54
|
.limitBy(3, 'category')
|
|
85
55
|
.execute();
|
|
86
56
|
```
|
|
87
57
|
|
|
88
|
-
|
|
89
|
-
const explodedTags = await db
|
|
90
|
-
.table('products')
|
|
91
|
-
.select(['id', 'tags'])
|
|
92
|
-
.arrayJoin('tags')
|
|
93
|
-
.execute();
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
`arrayJoin()` and `leftArrayJoin()` only accept array-typed columns.
|
|
97
|
-
|
|
98
|
-
## Browser Use
|
|
99
|
-
|
|
100
|
-
In browser environments, create the ClickHouse client explicitly and inject it:
|
|
101
|
-
|
|
102
|
-
```ts
|
|
103
|
-
import { createClient } from '@clickhouse/client-web';
|
|
104
|
-
import { createQueryBuilder } from '@hypequery/clickhouse';
|
|
105
|
-
import type { IntrospectedSchema } from './analytics/schema.js';
|
|
106
|
-
|
|
107
|
-
const client = createClient({
|
|
108
|
-
url: process.env.NEXT_PUBLIC_CLICKHOUSE_URL!,
|
|
109
|
-
username: process.env.NEXT_PUBLIC_CLICKHOUSE_USERNAME!,
|
|
110
|
-
password: process.env.NEXT_PUBLIC_CLICKHOUSE_PASSWORD ?? '',
|
|
111
|
-
database: process.env.NEXT_PUBLIC_CLICKHOUSE_DATABASE!,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
const db = createQueryBuilder<IntrospectedSchema>({
|
|
115
|
-
client,
|
|
116
|
-
});
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
## Schema Generation
|
|
120
|
-
|
|
121
|
-
The usual path is through the CLI:
|
|
122
|
-
|
|
123
|
-
```bash
|
|
124
|
-
npm install -D @hypequery/cli
|
|
125
|
-
npx hypequery generate
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
The package also ships the lower-level generator binary:
|
|
129
|
-
|
|
130
|
-
```bash
|
|
131
|
-
npx hypequery-generate-types
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
More details: [README-CLI.md](./README-CLI.md)
|
|
58
|
+
See [what hypequery supports today](https://hypequery.com/docs/capabilities) for the exact public surface.
|
|
135
59
|
|
|
136
|
-
##
|
|
60
|
+
## Grow beyond one query
|
|
137
61
|
|
|
138
|
-
|
|
139
|
-
- exported time helpers like `toStartOfMinute`, `toStartOfHour`, `toStartOfDay`, `toStartOfWeek`, `toStartOfMonth`, `toStartOfQuarter`, and `toStartOfYear`
|
|
140
|
-
- cache primitives like `MemoryCacheProvider`
|
|
62
|
+
When analytics meaning needs to be shared, add `@hypequery/datasets` for a code-first semantic layer, `@hypequery/serve` for validated APIs, `@hypequery/react` for typed hooks, and `@hypequery/mcp` for governed AI-agent access. They all build on this query layer.
|
|
141
63
|
|
|
142
|
-
##
|
|
64
|
+
## Learn more
|
|
143
65
|
|
|
144
|
-
- [
|
|
66
|
+
- [Quick start](https://hypequery.com/docs/quick-start)
|
|
67
|
+
- [Query builder guide](https://hypequery.com/clickhouse-query-builder)
|
|
145
68
|
- [Filtering](https://hypequery.com/docs/query-building/where)
|
|
146
|
-
- [Joins](https://hypequery.com/docs/query-building/joins)
|
|
147
69
|
- [Aggregation](https://hypequery.com/docs/query-building/aggregation)
|
|
148
|
-
- [
|
|
70
|
+
- [Schema generation](./README-CLI.md)
|
|
149
71
|
|
|
150
72
|
## License
|
|
151
73
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypequery/clickhouse",
|
|
3
|
-
"version": "2.5.
|
|
4
|
-
"description": "ClickHouse
|
|
3
|
+
"version": "2.5.5",
|
|
4
|
+
"description": "Type-safe ClickHouse query builder and schema generator for TypeScript analytics",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"clickhouse",
|
|
7
|
+
"typescript",
|
|
8
|
+
"query-builder",
|
|
9
|
+
"type-safe",
|
|
10
|
+
"analytics",
|
|
11
|
+
"semantic-layer",
|
|
12
|
+
"orm",
|
|
13
|
+
"olap",
|
|
14
|
+
"sql",
|
|
15
|
+
"schema-generation"
|
|
16
|
+
],
|
|
5
17
|
"main": "dist/index.js",
|
|
6
18
|
"types": "dist/index.d.ts",
|
|
7
19
|
"type": "module",
|
|
@@ -36,7 +48,7 @@
|
|
|
36
48
|
"dependencies": {
|
|
37
49
|
"@clickhouse/client": "^1.18.3",
|
|
38
50
|
"dotenv": "^16.0.0",
|
|
39
|
-
"@hypequery/protocol": "0.10.
|
|
51
|
+
"@hypequery/protocol": "0.10.2"
|
|
40
52
|
},
|
|
41
53
|
"peerDependencies": {
|
|
42
54
|
"@clickhouse/client-web": "^0.2.0 || ^1.0.0",
|
|
@@ -62,7 +74,7 @@
|
|
|
62
74
|
"typescript": "^5.7.3",
|
|
63
75
|
"@vitest/coverage-v8": "^3.2.6",
|
|
64
76
|
"vitest": "^3.2.6",
|
|
65
|
-
"@hypequery/datasets": "0.13.
|
|
77
|
+
"@hypequery/datasets": "0.13.3"
|
|
66
78
|
},
|
|
67
79
|
"ts-node": {
|
|
68
80
|
"esm": true,
|
|
@@ -70,7 +82,8 @@
|
|
|
70
82
|
},
|
|
71
83
|
"repository": {
|
|
72
84
|
"type": "git",
|
|
73
|
-
"url": "https://github.com/hypequery/hypequery.git"
|
|
85
|
+
"url": "git+https://github.com/hypequery/hypequery.git",
|
|
86
|
+
"directory": "packages/clickhouse"
|
|
74
87
|
},
|
|
75
88
|
"homepage": "https://hypequery.com",
|
|
76
89
|
"bugs": {
|