@hypequery/clickhouse 0.2.1 → 0.2.2-beta.0
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 +1 -1
- package/dist/cli/bin.js +129 -37
- package/dist/cli/generate-types.js +104 -15
- package/dist/core/connection.d.ts +112 -0
- package/dist/core/connection.d.ts.map +1 -1
- package/dist/core/connection.js +148 -25
- package/dist/core/cross-filter.d.ts +69 -0
- package/dist/core/cross-filter.d.ts.map +1 -1
- package/dist/core/cross-filter.js +1 -83
- package/dist/core/features/aggregations.d.ts +102 -0
- package/dist/core/features/analytics.d.ts +66 -0
- package/dist/core/features/analytics.d.ts.map +1 -1
- package/dist/core/features/cross-filtering.d.ts +31 -0
- package/dist/core/features/cross-filtering.d.ts.map +1 -0
- package/dist/core/features/cross-filtering.js +123 -0
- package/dist/core/features/executor.d.ts +19 -0
- package/dist/core/features/executor.js +3 -3
- package/dist/core/features/filtering.d.ts +95 -0
- package/dist/core/features/filtering.d.ts.map +1 -1
- package/dist/core/features/filtering.js +89 -3
- package/dist/core/features/joins.d.ts +29 -0
- package/dist/core/features/pagination.d.ts +23 -0
- package/dist/core/features/query-modifiers.d.ts +119 -0
- package/dist/core/formatters/sql-formatter.d.ts +9 -0
- package/dist/core/formatters/sql-formatter.d.ts.map +1 -1
- package/dist/core/formatters/sql-formatter.js +61 -5
- package/dist/core/join-relationships.d.ts +50 -0
- package/dist/core/join-relationships.d.ts.map +1 -1
- package/dist/core/query-builder.d.ts +258 -0
- package/dist/core/query-builder.d.ts.map +1 -1
- package/dist/core/query-builder.js +88 -27
- package/dist/core/tests/index.d.ts +2 -0
- package/dist/core/tests/integration/pagination-test-tbc.d.ts +2 -0
- package/dist/core/tests/integration/pagination-test-tbc.d.ts.map +1 -0
- package/dist/core/tests/integration/pagination-test-tbc.js +189 -0
- package/dist/core/tests/integration/setup.d.ts +40 -0
- package/dist/core/tests/integration/setup.d.ts.map +1 -1
- package/dist/core/tests/integration/setup.js +279 -238
- package/dist/core/tests/integration/test-config.d.ts +15 -0
- package/dist/core/tests/integration/test-config.d.ts.map +1 -0
- package/dist/core/tests/integration/test-config.js +15 -0
- package/dist/core/tests/integration/test-initializer.d.ts +7 -0
- package/dist/core/tests/integration/test-initializer.d.ts.map +1 -0
- package/dist/core/tests/integration/test-initializer.js +32 -0
- package/dist/core/tests/test-utils.d.ts +29 -0
- package/dist/core/tests/test-utils.d.ts.map +1 -1
- package/dist/core/tests/test-utils.js +6 -2
- package/dist/core/utils/logger.d.ts +37 -0
- package/dist/core/utils/logger.js +6 -6
- package/dist/core/utils/sql-expressions.d.ts +63 -0
- package/dist/core/utils/sql-expressions.d.ts.map +1 -1
- package/dist/core/utils/sql-expressions.js +9 -5
- package/dist/core/utils.d.ts +3 -0
- package/dist/core/validators/filter-validator.d.ts +8 -0
- package/dist/core/validators/filter-validator.js +1 -1
- package/dist/core/validators/value-validator.d.ts +6 -0
- package/dist/formatters/index.d.ts +1 -0
- package/dist/index.d.ts +12 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -2
- package/dist/types/base.d.ts +77 -0
- package/dist/types/base.d.ts.map +1 -1
- package/dist/types/clickhouse-types.d.ts +13 -0
- package/dist/types/clickhouse-types.d.ts.map +1 -1
- package/dist/types/filters.d.ts +53 -0
- package/dist/types/filters.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -0
- package/package.json +36 -13
- package/README.md +0 -276
package/README.md
DELETED
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
# HypeQuery
|
|
2
|
-
|
|
3
|
-
<div align="center">
|
|
4
|
-
<img src="https://hypequery.dev/img/logo.svg" alt="HypeQuery Logo" width="200"/>
|
|
5
|
-
<h1>@hypequery/clickhouse</h1>
|
|
6
|
-
<p>A typescript-first library for building type-safe dashboards with ClickHouse</p>
|
|
7
|
-
|
|
8
|
-
[](https://github.com/lukejreilly/hypequery/blob/main/LICENSE)
|
|
9
|
-
[](https://badge.fury.io/js/@hypequery%2Fcore)
|
|
10
|
-
[](https://github.com/lukejreilly/hypequery/stargazers)
|
|
11
|
-
</div>
|
|
12
|
-
|
|
13
|
-
> **Note:** This package is published on npm as `@hypequery/core`. The unscoped package `hypequery-core` is unrelated and should not be used.
|
|
14
|
-
|
|
15
|
-
## Overview
|
|
16
|
-
|
|
17
|
-
hypequery is a typescript-first query builder for ClickHouse designed specifically for building real-time, type-safe analytics dashboards. Unlike generic SQL query builders, HypeQuery understands your ClickHouse schema and provides full type checking throughout your codebase, making it ideal for data-intensive applications.
|
|
18
|
-
|
|
19
|
-
## Features
|
|
20
|
-
|
|
21
|
-
- 🎯 **Type-Safe**: Full TypeScript support with inferred types from your ClickHouse schema
|
|
22
|
-
- 🚀 **Performant**: Built for real-time analytics with optimized query generation
|
|
23
|
-
- 🔍 **Cross Filtering**: Powerful cross-filtering capabilities for interactive dashboards
|
|
24
|
-
- 📊 **Dashboard Ready**: Built-in support for pagination, sorting, and filtering
|
|
25
|
-
- 🛠️ **Developer Friendly**: Fluent API design for an intuitive development experience
|
|
26
|
-
- 📱 **Platform Agnostic**: Works in both Node.js and browser environments
|
|
27
|
-
- 🔄 **Schema Generation**: CLI tool to generate TypeScript types from your ClickHouse schema
|
|
28
|
-
|
|
29
|
-
## Installation
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
# npm
|
|
33
|
-
npm install @hypequery/core
|
|
34
|
-
|
|
35
|
-
# yarn
|
|
36
|
-
yarn add @hypequery/core
|
|
37
|
-
|
|
38
|
-
# pnpm
|
|
39
|
-
pnpm add @hypequery/core
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Quick Start
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
import { createQueryBuilder } from '@hypequery/core';
|
|
46
|
-
import type { Schema } from './generated-schema';
|
|
47
|
-
|
|
48
|
-
// Initialize the query builder
|
|
49
|
-
const db = createQueryBuilder<Schema>({
|
|
50
|
-
host: 'your-clickhouse-host',
|
|
51
|
-
username: 'default',
|
|
52
|
-
password: '',
|
|
53
|
-
database: 'default'
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// Build and execute a query
|
|
57
|
-
const results = await db
|
|
58
|
-
.table('trips')
|
|
59
|
-
.select(['pickup_datetime', 'dropoff_datetime', 'total_amount'])
|
|
60
|
-
.where('total_amount', '>', 50)
|
|
61
|
-
.orderBy('pickup_datetime', 'DESC')
|
|
62
|
-
.limit(10)
|
|
63
|
-
.execute();
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Schema Generation
|
|
67
|
-
|
|
68
|
-
HypeQuery provides a CLI tool to generate TypeScript types from your ClickHouse schema:
|
|
69
|
-
|
|
70
|
-
```bash
|
|
71
|
-
# Install globally (optional)
|
|
72
|
-
npm install -g @hypequery/core
|
|
73
|
-
|
|
74
|
-
# Generate schema types
|
|
75
|
-
npx hypequery-generate --host your-clickhouse-host --database your-database
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
This creates a `generated-schema.ts` file that you can import in your application:
|
|
79
|
-
|
|
80
|
-
```typescript
|
|
81
|
-
import { createQueryBuilder } from '@hypequery/core';
|
|
82
|
-
import type { IntrospectedSchema } from './generated-schema';
|
|
83
|
-
|
|
84
|
-
const db = createQueryBuilder<IntrospectedSchema>({
|
|
85
|
-
// connection details
|
|
86
|
-
});
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
## Core Features
|
|
90
|
-
|
|
91
|
-
### Type-Safe Queries
|
|
92
|
-
|
|
93
|
-
HypeQuery provides full TypeScript support, ensuring your queries are type-safe:
|
|
94
|
-
|
|
95
|
-
```typescript
|
|
96
|
-
// Column names are type-checked
|
|
97
|
-
const query = db.table('trips')
|
|
98
|
-
.select(['pickup_datetime', 'total_amount'])
|
|
99
|
-
.where('total_amount', '>', 50)
|
|
100
|
-
.execute();
|
|
101
|
-
|
|
102
|
-
// Type error if column doesn't exist
|
|
103
|
-
db.table('trips').select(['non_existent_column']); // TypeScript error
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### Cross Filtering
|
|
107
|
-
|
|
108
|
-
Implement interactive dashboards with cross-filtering support:
|
|
109
|
-
|
|
110
|
-
```typescript
|
|
111
|
-
import { CrossFilter } from '@hypequery/core';
|
|
112
|
-
|
|
113
|
-
// Create a filter
|
|
114
|
-
const filter = new CrossFilter()
|
|
115
|
-
.add({
|
|
116
|
-
column: 'pickup_datetime',
|
|
117
|
-
operator: 'gte',
|
|
118
|
-
value: '2024-01-01'
|
|
119
|
-
})
|
|
120
|
-
.add({
|
|
121
|
-
column: 'total_amount',
|
|
122
|
-
operator: 'gt',
|
|
123
|
-
value: 20
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// Apply to multiple queries
|
|
127
|
-
const query1 = db.table('trips')
|
|
128
|
-
.applyCrossFilters(filter)
|
|
129
|
-
.execute();
|
|
130
|
-
|
|
131
|
-
const query2 = db.table('drivers')
|
|
132
|
-
.applyCrossFilters(filter)
|
|
133
|
-
.execute();
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
### Pagination
|
|
137
|
-
|
|
138
|
-
Built-in cursor-based pagination for efficient data loading:
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
// First page
|
|
142
|
-
const firstPage = await db.table('trips')
|
|
143
|
-
.select(['pickup_datetime', 'total_amount'])
|
|
144
|
-
.orderBy('pickup_datetime', 'DESC')
|
|
145
|
-
.paginate({
|
|
146
|
-
pageSize: 10
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// Next page
|
|
150
|
-
const nextPage = await db.table('trips')
|
|
151
|
-
.select(['pickup_datetime', 'total_amount'])
|
|
152
|
-
.orderBy('pickup_datetime', 'DESC')
|
|
153
|
-
.paginate({
|
|
154
|
-
pageSize: 10,
|
|
155
|
-
after: firstPage.pageInfo.endCursor
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// Previous page
|
|
159
|
-
const prevPage = await db.table('trips')
|
|
160
|
-
.select(['pickup_datetime', 'total_amount'])
|
|
161
|
-
.orderBy('pickup_datetime', 'DESC')
|
|
162
|
-
.paginate({
|
|
163
|
-
pageSize: 10,
|
|
164
|
-
before: nextPage.pageInfo.startCursor
|
|
165
|
-
});
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
### Advanced Queries
|
|
169
|
-
|
|
170
|
-
HypeQuery supports complex queries including joins, aggregations, and subqueries:
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
// Aggregations
|
|
174
|
-
const stats = await db.table('trips')
|
|
175
|
-
.avg('total_amount')
|
|
176
|
-
.max('trip_distance')
|
|
177
|
-
.count('trip_id')
|
|
178
|
-
.where('pickup_datetime', '>=', '2024-01-01')
|
|
179
|
-
.execute();
|
|
180
|
-
|
|
181
|
-
// Joins
|
|
182
|
-
const tripsWithDrivers = await db.table('trips')
|
|
183
|
-
.select(['trips.trip_id', 'trips.total_amount', 'drivers.name'])
|
|
184
|
-
.join('drivers', 'trips.driver_id', '=', 'drivers.id')
|
|
185
|
-
.execute();
|
|
186
|
-
|
|
187
|
-
// Raw SQL when needed
|
|
188
|
-
const customQuery = await db.table('trips')
|
|
189
|
-
.select([
|
|
190
|
-
db.raw('toStartOfDay(pickup_datetime) as day'),
|
|
191
|
-
'count() as trip_count'
|
|
192
|
-
])
|
|
193
|
-
.groupBy(db.raw('toStartOfDay(pickup_datetime)'))
|
|
194
|
-
.execute();
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
## Environment Support
|
|
198
|
-
|
|
199
|
-
### Browser Environment
|
|
200
|
-
|
|
201
|
-
For browser usage, you'll typically need to set up a proxy server to avoid CORS issues:
|
|
202
|
-
|
|
203
|
-
```typescript
|
|
204
|
-
const db = createQueryBuilder<Schema>({
|
|
205
|
-
host: '/api/clickhouse', // Proxy through your API route
|
|
206
|
-
username: 'default',
|
|
207
|
-
password: '',
|
|
208
|
-
database: 'default'
|
|
209
|
-
});
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
### Node.js Environment
|
|
213
|
-
|
|
214
|
-
For server-side applications, you can connect directly to ClickHouse:
|
|
215
|
-
|
|
216
|
-
```typescript
|
|
217
|
-
const db = createQueryBuilder<Schema>({
|
|
218
|
-
host: 'http://your-clickhouse-server:8123',
|
|
219
|
-
username: 'default',
|
|
220
|
-
password: 'your-password',
|
|
221
|
-
database: 'default'
|
|
222
|
-
});
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
## Versioning and Release Channels
|
|
226
|
-
|
|
227
|
-
HypeQuery follows semantic versioning and provides multiple release channels:
|
|
228
|
-
|
|
229
|
-
- **Latest**: Stable releases (`npm install @hypequery/core`)
|
|
230
|
-
- **Beta**: Pre-release versions (`npm install @hypequery/core@beta`)
|
|
231
|
-
|
|
232
|
-
## Documentation
|
|
233
|
-
|
|
234
|
-
For detailed documentation and examples, visit our [documentation site](https://hypequery.dev/docs).
|
|
235
|
-
|
|
236
|
-
- [Getting Started](https://hypequery.dev/docs/installation)
|
|
237
|
-
- [Query Building](https://hypequery.dev/docs/guides/query-building)
|
|
238
|
-
- [Filtering](https://hypequery.dev/docs/guides/filtering)
|
|
239
|
-
- [Pagination](https://hypequery.dev/docs/features/pagination)
|
|
240
|
-
- [API Reference](https://hypequery.dev/docs/reference/api)
|
|
241
|
-
|
|
242
|
-
## Examples
|
|
243
|
-
|
|
244
|
-
Check out our example implementations:
|
|
245
|
-
|
|
246
|
-
- [Example Dashboard](https://github.com/lukejreilly/hypequery/tree/main/examples/example-dashboard): A complete Next.js dashboard with HypeQuery
|
|
247
|
-
- [React Query Integration](https://hypequery.dev/docs/guides/integrations/react-query): Using HypeQuery with React Query
|
|
248
|
-
- [Time Series Analysis](https://hypequery.dev/docs/guides/timeseries): Building time series analytics
|
|
249
|
-
|
|
250
|
-
## Troubleshooting
|
|
251
|
-
|
|
252
|
-
### Common Issues
|
|
253
|
-
|
|
254
|
-
- **Connection Errors**: Ensure your ClickHouse server is running and accessible
|
|
255
|
-
- **CORS Issues**: Use a proxy server for browser environments
|
|
256
|
-
- **Type Errors**: Make sure to regenerate your schema types after schema changes
|
|
257
|
-
|
|
258
|
-
## Contributing
|
|
259
|
-
|
|
260
|
-
We welcome contributions! Please see our [contributing guide](CONTRIBUTING.md) for details.
|
|
261
|
-
|
|
262
|
-
## License
|
|
263
|
-
|
|
264
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
265
|
-
|
|
266
|
-
## Support
|
|
267
|
-
|
|
268
|
-
- 📚 [Documentation](https://hypequery.dev/docs)
|
|
269
|
-
- 🐛 [Issue Tracker](https://github.com/lukejreilly/hypequery/issues)
|
|
270
|
-
- 💬 [Discussions](https://github.com/lukejreilly/hypequery/discussions)
|
|
271
|
-
|
|
272
|
-
---
|
|
273
|
-
|
|
274
|
-
<div align="center">
|
|
275
|
-
<sub>Built with ❤️ by the HypeQuery team</sub>
|
|
276
|
-
</div>
|