@hypequery/clickhouse 1.0.5 → 1.1.1
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.md +74 -100
- package/dist/core/connection.d.ts +53 -77
- package/dist/core/connection.d.ts.map +1 -1
- package/dist/core/connection.js +93 -28
- package/dist/core/cross-filter.d.ts +0 -16
- package/dist/core/cross-filter.d.ts.map +1 -1
- package/dist/core/cross-filter.js +0 -82
- package/dist/core/features/analytics.d.ts +1 -1
- package/dist/core/features/analytics.d.ts.map +1 -1
- package/dist/core/query-builder.d.ts +33 -19
- package/dist/core/query-builder.d.ts.map +1 -1
- package/dist/core/query-builder.js +12 -0
- package/dist/core/tests/integration/setup.d.ts +1 -1
- package/dist/core/tests/integration/setup.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +16 -2
package/README.md
CHANGED
|
@@ -1,61 +1,90 @@
|
|
|
1
|
-
# hypequery
|
|
2
|
-
|
|
3
1
|
<div align="center">
|
|
4
|
-
<img src="https://hypequery.dev/img/logo.svg" alt="hypequery Logo" width="200"/>
|
|
5
2
|
<h1>@hypequery/clickhouse</h1>
|
|
6
3
|
<p>A typescript-first library for building type-safe dashboards with ClickHouse</p>
|
|
7
4
|
|
|
8
|
-
[](https://github.com/hypequery/hypequery/blob/main/LICENSE)
|
|
6
|
+
[](https://badge.fury.io/js/@hypequery%2Fclickhouse)
|
|
7
|
+
[](https://github.com/hypequery/hypequery/stargazers)
|
|
11
8
|
</div>
|
|
12
9
|
|
|
13
10
|
|
|
14
11
|
## Overview
|
|
15
12
|
|
|
16
|
-
hypequery is a typescript-first query builder for ClickHouse designed specifically for building
|
|
13
|
+
hypequery is a typescript-first query builder for ClickHouse designed specifically for building type-safe analytics dashboards. Unlike generic SQL query builders, hypequery understands your ClickHouse schema and provides full type checking, making it ideal for data-intensive applications.
|
|
17
14
|
|
|
18
15
|
## Features
|
|
19
16
|
|
|
20
|
-
- 🎯 **Type-Safe**: Full TypeScript support with
|
|
17
|
+
- 🎯 **Type-Safe**: Full TypeScript support with types from your ClickHouse schema
|
|
21
18
|
- 🚀 **Performant**: Built for real-time analytics with optimized query generation
|
|
22
19
|
- 🔍 **Cross Filtering**: Powerful cross-filtering capabilities for interactive dashboards
|
|
23
|
-
- 📊 **Dashboard Ready**: Built-in support for pagination, sorting, and filtering
|
|
24
20
|
- 🛠️ **Developer Friendly**: Fluent API design for an intuitive development experience
|
|
25
21
|
- 📱 **Platform Agnostic**: Works in both Node.js and browser environments
|
|
26
22
|
- 🔄 **Schema Generation**: CLI tool to generate TypeScript types from your ClickHouse schema
|
|
27
23
|
|
|
28
24
|
## Installation
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
npm install @hypequery/clickhouse
|
|
33
|
-
```
|
|
26
|
+
This library requires one of the following ClickHouse clients as a peer dependency:
|
|
34
27
|
|
|
35
|
-
###
|
|
28
|
+
### For Node.js environments
|
|
36
29
|
```bash
|
|
37
|
-
|
|
30
|
+
npm install @hypequery/clickhouse @clickhouse/client
|
|
38
31
|
```
|
|
39
32
|
|
|
40
|
-
###
|
|
33
|
+
### For browser/universal environments
|
|
41
34
|
```bash
|
|
42
|
-
|
|
35
|
+
npm install @hypequery/clickhouse @clickhouse/client-web
|
|
43
36
|
```
|
|
44
37
|
|
|
38
|
+
**Note**: The library supports multiple client selection strategies:
|
|
39
|
+
- **Manual injection**: Explicitly provide a client instance (required for browser environments)
|
|
40
|
+
- **Auto-detection**: Automatically selects the client for Node.js environments
|
|
41
|
+
|
|
45
42
|
## Quick Start
|
|
46
43
|
|
|
44
|
+
### Node.js Environments
|
|
45
|
+
|
|
47
46
|
```typescript
|
|
48
47
|
import { createQueryBuilder } from '@hypequery/clickhouse';
|
|
49
|
-
import type {
|
|
48
|
+
import type { IntrospectedSchema } from './generated-schema';
|
|
50
49
|
|
|
51
50
|
// Initialize the query builder
|
|
52
|
-
const db = createQueryBuilder<
|
|
51
|
+
const db = createQueryBuilder<IntrospectedSchema>({
|
|
52
|
+
host: 'your-clickhouse-host',
|
|
53
|
+
username: 'default',
|
|
54
|
+
password: 'your-password',
|
|
55
|
+
database: 'default'
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Build and execute a query
|
|
59
|
+
const results = await db
|
|
60
|
+
.table('trips')
|
|
61
|
+
.select(['pickup_datetime', 'dropoff_datetime', 'total_amount'])
|
|
62
|
+
.where('total_amount', '>', 50)
|
|
63
|
+
.orderBy('pickup_datetime', 'DESC')
|
|
64
|
+
.limit(10)
|
|
65
|
+
.execute();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Browser Environments
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { createQueryBuilder } from '@hypequery/clickhouse';
|
|
72
|
+
import { createClient } from '@clickhouse/client-web';
|
|
73
|
+
import type { IntrospectedSchema } from './generated-schema';
|
|
74
|
+
|
|
75
|
+
// Create the ClickHouse client explicitly
|
|
76
|
+
const client = createClient({
|
|
53
77
|
host: 'your-clickhouse-host',
|
|
54
78
|
username: 'default',
|
|
55
79
|
password: '',
|
|
56
80
|
database: 'default'
|
|
57
81
|
});
|
|
58
82
|
|
|
83
|
+
// Initialize the query builder with the client
|
|
84
|
+
const db = createQueryBuilder<IntrospectedSchema>({
|
|
85
|
+
client // Explicitly provide the client
|
|
86
|
+
});
|
|
87
|
+
|
|
59
88
|
// Build and execute a query
|
|
60
89
|
const results = await db
|
|
61
90
|
.table('trips')
|
|
@@ -75,7 +104,7 @@ hypequery provides a CLI tool to generate TypeScript types from your ClickHouse
|
|
|
75
104
|
npm install -g @hypequery/clickhouse
|
|
76
105
|
|
|
77
106
|
# Generate schema types
|
|
78
|
-
npx hypequery-generate --host your-clickhouse-host --database your-database
|
|
107
|
+
npx hypequery-generate-types --host your-clickhouse-host --database your-database
|
|
79
108
|
```
|
|
80
109
|
|
|
81
110
|
This creates a `generated-schema.ts` file that you can import in your application:
|
|
@@ -99,7 +128,7 @@ hypequery provides full TypeScript support, ensuring your queries are type-safe:
|
|
|
99
128
|
// Column names are type-checked
|
|
100
129
|
const query = db.table('trips')
|
|
101
130
|
.select(['pickup_datetime', 'total_amount'])
|
|
102
|
-
.where('total_amount', '
|
|
131
|
+
.where('total_amount', 'gt', 50)
|
|
103
132
|
.execute();
|
|
104
133
|
|
|
105
134
|
// Type error if column doesn't exist
|
|
@@ -136,38 +165,6 @@ const query2 = db.table('drivers')
|
|
|
136
165
|
.execute();
|
|
137
166
|
```
|
|
138
167
|
|
|
139
|
-
### Pagination
|
|
140
|
-
|
|
141
|
-
Built-in cursor-based pagination for efficient data loading:
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
// First page
|
|
145
|
-
const firstPage = await db.table('trips')
|
|
146
|
-
.select(['pickup_datetime', 'total_amount'])
|
|
147
|
-
.orderBy('pickup_datetime', 'DESC')
|
|
148
|
-
.paginate({
|
|
149
|
-
pageSize: 10
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
// Next page
|
|
153
|
-
const nextPage = await db.table('trips')
|
|
154
|
-
.select(['pickup_datetime', 'total_amount'])
|
|
155
|
-
.orderBy('pickup_datetime', 'DESC')
|
|
156
|
-
.paginate({
|
|
157
|
-
pageSize: 10,
|
|
158
|
-
after: firstPage.pageInfo.endCursor
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
// Previous page
|
|
162
|
-
const prevPage = await db.table('trips')
|
|
163
|
-
.select(['pickup_datetime', 'total_amount'])
|
|
164
|
-
.orderBy('pickup_datetime', 'DESC')
|
|
165
|
-
.paginate({
|
|
166
|
-
pageSize: 10,
|
|
167
|
-
before: nextPage.pageInfo.startCursor
|
|
168
|
-
});
|
|
169
|
-
```
|
|
170
|
-
|
|
171
168
|
### Advanced Queries
|
|
172
169
|
|
|
173
170
|
hypequery supports complex queries including joins, aggregations, and subqueries:
|
|
@@ -178,52 +175,35 @@ const stats = await db.table('trips')
|
|
|
178
175
|
.avg('total_amount')
|
|
179
176
|
.max('trip_distance')
|
|
180
177
|
.count('trip_id')
|
|
181
|
-
.where('pickup_datetime', '
|
|
178
|
+
.where('pickup_datetime', 'gte', '2024-01-01')
|
|
182
179
|
.execute();
|
|
183
180
|
|
|
184
181
|
// Joins
|
|
185
182
|
const tripsWithDrivers = await db.table('trips')
|
|
186
183
|
.select(['trips.trip_id', 'trips.total_amount', 'drivers.name'])
|
|
187
|
-
.join('drivers', 'trips.driver_id', '
|
|
184
|
+
.join('drivers', 'trips.driver_id', 'drivers.id')
|
|
188
185
|
.execute();
|
|
189
186
|
|
|
190
|
-
// Raw SQL when needed
|
|
191
|
-
const customQuery = await db.table('trips')
|
|
192
|
-
.select([
|
|
193
|
-
db.raw('toStartOfDay(pickup_datetime) as day'),
|
|
194
|
-
'count() as trip_count'
|
|
195
|
-
])
|
|
196
|
-
.groupBy(db.raw('toStartOfDay(pickup_datetime)'))
|
|
197
|
-
.execute();
|
|
198
187
|
```
|
|
199
188
|
|
|
200
|
-
## Environment Support
|
|
201
189
|
|
|
202
|
-
|
|
190
|
+
**Benefits:**
|
|
191
|
+
- ✅ Works in all environments (Node.js, browser, bundlers)
|
|
192
|
+
- ✅ Explicit control over client configuration
|
|
193
|
+
- ✅ Required for browser environments (require() doesn't work in browsers)
|
|
194
|
+
- ✅ Synchronous API throughout
|
|
203
195
|
|
|
204
|
-
|
|
196
|
+
#### 2. Auto-Detection with Fallback (Node.js Environments Only)
|
|
205
197
|
|
|
206
198
|
```typescript
|
|
207
|
-
const db = createQueryBuilder<
|
|
208
|
-
host: '
|
|
199
|
+
const db = createQueryBuilder<IntrospectedSchema>({
|
|
200
|
+
host: 'your-clickhouse-host',
|
|
209
201
|
username: 'default',
|
|
210
202
|
password: '',
|
|
211
203
|
database: 'default'
|
|
212
204
|
});
|
|
213
205
|
```
|
|
214
206
|
|
|
215
|
-
### Node.js Environment
|
|
216
|
-
|
|
217
|
-
For server-side applications, you can connect directly to ClickHouse:
|
|
218
|
-
|
|
219
|
-
```typescript
|
|
220
|
-
const db = createQueryBuilder<Schema>({
|
|
221
|
-
host: 'http://your-clickhouse-server:8123',
|
|
222
|
-
username: 'default',
|
|
223
|
-
password: 'your-password',
|
|
224
|
-
database: 'default'
|
|
225
|
-
});
|
|
226
|
-
```
|
|
227
207
|
|
|
228
208
|
## Versioning and Release Channels
|
|
229
209
|
|
|
@@ -234,21 +214,14 @@ hypequery follows semantic versioning and provides multiple release channels:
|
|
|
234
214
|
|
|
235
215
|
## Documentation
|
|
236
216
|
|
|
237
|
-
For detailed documentation and examples, visit our [documentation site](https://hypequery.
|
|
217
|
+
For detailed documentation and examples, visit our [documentation site](https://hypequery.com/docs).
|
|
238
218
|
|
|
239
|
-
- [Getting Started](https://hypequery.
|
|
240
|
-
- [Query Building](https://hypequery.
|
|
241
|
-
- [Filtering](https://hypequery.
|
|
242
|
-
- [Pagination](https://hypequery.
|
|
243
|
-
- [API Reference](https://hypequery.
|
|
219
|
+
- [Getting Started](https://hypequery.com/docs/installation)
|
|
220
|
+
- [Query Building](https://hypequery.com/docs/guides/query-building)
|
|
221
|
+
- [Filtering](https://hypequery.com/docs/guides/filtering)
|
|
222
|
+
- [Pagination](https://hypequery.com/docs/features/pagination)
|
|
223
|
+
- [API Reference](https://hypequery.com/docs/reference/api)
|
|
244
224
|
|
|
245
|
-
## Examples
|
|
246
|
-
|
|
247
|
-
Check out our example implementations:
|
|
248
|
-
|
|
249
|
-
- [Example Dashboard](https://github.com/lukejreilly/hypequery/tree/main/examples/example-dashboard): A complete Next.js dashboard with hypequery
|
|
250
|
-
- [React Query Integration](https://hypequery.dev/docs/guides/integrations/react-query): Using hypequery with React Query
|
|
251
|
-
- [Time Series Analysis](https://hypequery.dev/docs/guides/timeseries): Building time series analytics
|
|
252
225
|
|
|
253
226
|
## Troubleshooting
|
|
254
227
|
|
|
@@ -257,20 +230,21 @@ Check out our example implementations:
|
|
|
257
230
|
- **Connection Errors**: Ensure your ClickHouse server is running and accessible
|
|
258
231
|
- **CORS Issues**: Use a proxy server for browser environments
|
|
259
232
|
- **Type Errors**: Make sure to regenerate your schema types after schema changes
|
|
233
|
+
- **Client Not Found**: Make sure you have installed at least one of the required peer dependencies:
|
|
234
|
+
- `@clickhouse/client` (for Node.js environments)
|
|
235
|
+
- `@clickhouse/client-web` (for browser/universal environments)
|
|
236
|
+
- **Browser Auto-Detection**: Auto-detection doesn't work in browsers because `require()` calls don't work. Use manual injection instead.
|
|
260
237
|
|
|
261
|
-
## Contributing
|
|
262
|
-
|
|
263
|
-
We welcome contributions! Please see our [contributing guide](CONTRIBUTING.md) for details.
|
|
264
238
|
|
|
265
239
|
## License
|
|
266
240
|
|
|
267
|
-
This project is licensed under the
|
|
241
|
+
This project is licensed under the Apache-2.0 License - see the [LICENSE](LICENSE) file for details.
|
|
268
242
|
|
|
269
243
|
## Support
|
|
270
244
|
|
|
271
|
-
- 📚 [Documentation](https://hypequery.
|
|
272
|
-
- 🐛 [Issue Tracker](https://github.com/
|
|
273
|
-
- 💬 [Discussions](https://github.com/
|
|
245
|
+
- 📚 [Documentation](https://hypequery.com/docs)
|
|
246
|
+
- 🐛 [Issue Tracker](https://github.com/hypequery/hypequery/issues)
|
|
247
|
+
- 💬 [Discussions](https://github.com/hypequery/hypequery/discussions)
|
|
274
248
|
|
|
275
249
|
---
|
|
276
250
|
|
|
@@ -1,84 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import type { ClickHouseSettings } from '@clickhouse/client-common';
|
|
2
|
+
import type { ClickHouseClient as NodeClickHouseClient } from '@clickhouse/client';
|
|
3
|
+
import type { ClickHouseClient as WebClickHouseClient } from '@clickhouse/client-web';
|
|
4
|
+
import type { ClickHouseConfig } from './query-builder';
|
|
5
|
+
type ClickHouseClient = NodeClickHouseClient | WebClickHouseClient;
|
|
3
6
|
/**
|
|
4
|
-
*
|
|
7
|
+
* The main entry point for connecting to a ClickHouse database.
|
|
8
|
+
* Provides static methods to initialize the connection and retrieve the client.
|
|
9
|
+
*
|
|
10
|
+
* Supports two modes of operation:
|
|
11
|
+
* 1. **Manual injection**: Provide a client instance via `config.client` (required for browser environments)
|
|
12
|
+
* 2. **Auto-detection**: Automatically uses @clickhouse/client for Node.js environments
|
|
5
13
|
*
|
|
6
14
|
* @category Core
|
|
7
15
|
* @example
|
|
8
16
|
* ```typescript
|
|
9
|
-
*
|
|
17
|
+
* // Method 1: Manual injection (required for browser environments)
|
|
18
|
+
* import { createClient } from '@clickhouse/client-web';
|
|
19
|
+
* const client = createClient({
|
|
10
20
|
* host: 'http://localhost:8123',
|
|
11
21
|
* username: 'default',
|
|
12
|
-
* password: 'password'
|
|
13
|
-
*
|
|
14
|
-
* };
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export interface ClickHouseConnectionOptions {
|
|
18
|
-
/**
|
|
19
|
-
* The URL of the ClickHouse server, including protocol and port.
|
|
20
|
-
* Example: 'http://localhost:8123' or 'https://your-instance.clickhouse.cloud:8443'
|
|
21
|
-
*/
|
|
22
|
-
host: string;
|
|
23
|
-
/**
|
|
24
|
-
* Username for authentication. Defaults to 'default' if not provided.
|
|
25
|
-
*/
|
|
26
|
-
username?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Password for authentication.
|
|
29
|
-
*/
|
|
30
|
-
password?: string;
|
|
31
|
-
/**
|
|
32
|
-
* The database to connect to. Defaults to 'default' if not provided.
|
|
33
|
-
*/
|
|
34
|
-
database?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Enable secure connection (TLS/SSL).
|
|
37
|
-
* This is automatically set to true if the host URL starts with https://
|
|
38
|
-
*/
|
|
39
|
-
secure?: boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Custom HTTP headers to include with each request.
|
|
42
|
-
*/
|
|
43
|
-
http_headers?: Record<string, string>;
|
|
44
|
-
/**
|
|
45
|
-
* Request timeout in milliseconds.
|
|
46
|
-
*/
|
|
47
|
-
request_timeout?: number;
|
|
48
|
-
/**
|
|
49
|
-
* Compression options for the connection.
|
|
50
|
-
*/
|
|
51
|
-
compression?: {
|
|
52
|
-
response?: boolean;
|
|
53
|
-
request?: boolean;
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Application name to identify in ClickHouse server logs.
|
|
57
|
-
*/
|
|
58
|
-
application?: string;
|
|
59
|
-
/**
|
|
60
|
-
* Keep-alive connection settings.
|
|
61
|
-
*/
|
|
62
|
-
keep_alive?: {
|
|
63
|
-
enabled: boolean;
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Logger configuration.
|
|
67
|
-
*/
|
|
68
|
-
log?: any;
|
|
69
|
-
/**
|
|
70
|
-
* Additional ClickHouse-specific settings.
|
|
71
|
-
*/
|
|
72
|
-
clickhouse_settings?: ClickHouseSettings;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* The main entry point for connecting to a ClickHouse database.
|
|
76
|
-
* Provides static methods to initialize the connection and retrieve the client.
|
|
22
|
+
* password: 'password'
|
|
23
|
+
* });
|
|
77
24
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* //
|
|
25
|
+
* ClickHouseConnection.initialize({
|
|
26
|
+
* host: 'http://localhost:8123',
|
|
27
|
+
* database: 'my_database',
|
|
28
|
+
* client // Explicitly provide the client
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Method 2: Auto-detection (Node.js environments only)
|
|
82
32
|
* ClickHouseConnection.initialize({
|
|
83
33
|
* host: 'http://localhost:8123',
|
|
84
34
|
* username: 'default',
|
|
@@ -93,20 +43,38 @@ export interface ClickHouseConnectionOptions {
|
|
|
93
43
|
* format: 'JSONEachRow'
|
|
94
44
|
* });
|
|
95
45
|
* ```
|
|
46
|
+
*
|
|
47
|
+
* @note This library requires one of the following peer dependencies:
|
|
48
|
+
* - @clickhouse/client (for Node.js environments)
|
|
49
|
+
* - @clickhouse/client-web (for browser environments)
|
|
50
|
+
*
|
|
51
|
+
* **Important**: Browser environments require manual injection because `require()` calls don't work in browsers.
|
|
96
52
|
*/
|
|
97
53
|
export declare class ClickHouseConnection {
|
|
98
54
|
private static instance;
|
|
55
|
+
private static clientModule;
|
|
99
56
|
/**
|
|
100
57
|
* Initializes the ClickHouse connection with the provided configuration.
|
|
101
58
|
* This method must be called before any queries can be executed.
|
|
102
59
|
*
|
|
60
|
+
* **Priority order:**
|
|
61
|
+
* 1. If `config.client` is provided, use it directly (manual injection)
|
|
62
|
+
* 2. Otherwise, auto-detect @clickhouse/client for Node.js environments
|
|
63
|
+
*
|
|
64
|
+
* **Note**: Browser environments require manual injection because `require()` calls don't work in browsers.
|
|
65
|
+
*
|
|
103
66
|
* @param config - The connection configuration options
|
|
104
67
|
* @returns The ClickHouseConnection class for method chaining
|
|
105
|
-
* @throws Will throw an error if
|
|
68
|
+
* @throws Will throw an error if no ClickHouse client is available
|
|
106
69
|
*
|
|
107
70
|
* @example
|
|
108
71
|
* ```typescript
|
|
109
|
-
* //
|
|
72
|
+
* // Manual injection (required for browser environments)
|
|
73
|
+
* import { createClient } from '@clickhouse/client-web';
|
|
74
|
+
* const client = createClient({ host: 'http://localhost:8123' });
|
|
75
|
+
* ClickHouseConnection.initialize({ host: 'http://localhost:8123', client });
|
|
76
|
+
*
|
|
77
|
+
* // Auto-detection (Node.js environments only)
|
|
110
78
|
* ClickHouseConnection.initialize({
|
|
111
79
|
* host: 'http://localhost:8123',
|
|
112
80
|
* username: 'default',
|
|
@@ -115,7 +83,7 @@ export declare class ClickHouseConnection {
|
|
|
115
83
|
* });
|
|
116
84
|
* ```
|
|
117
85
|
*/
|
|
118
|
-
static initialize(config:
|
|
86
|
+
static initialize(config: ClickHouseConfig): typeof ClickHouseConnection;
|
|
119
87
|
/**
|
|
120
88
|
* Retrieves the ClickHouse client instance for direct query execution.
|
|
121
89
|
*
|
|
@@ -131,6 +99,14 @@ export declare class ClickHouseConnection {
|
|
|
131
99
|
* });
|
|
132
100
|
* ```
|
|
133
101
|
*/
|
|
134
|
-
static getClient():
|
|
102
|
+
static getClient(): ClickHouseClient;
|
|
103
|
+
/**
|
|
104
|
+
* Gets the ClickHouseSettings type from the loaded client module.
|
|
105
|
+
* Only available when using auto-detection (not manual injection).
|
|
106
|
+
*
|
|
107
|
+
* @returns The ClickHouseSettings type or an empty object if not available
|
|
108
|
+
*/
|
|
109
|
+
static getClickHouseSettings(): ClickHouseSettings;
|
|
135
110
|
}
|
|
111
|
+
export {};
|
|
136
112
|
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/core/connection.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/core/connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,gBAAgB,IAAI,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAwB,MAAM,iBAAiB,CAAC;AAI9E,KAAK,gBAAgB,GAAG,oBAAoB,GAAG,mBAAmB,CAAC;AA+CnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAiC;IACxD,OAAO,CAAC,MAAM,CAAC,YAAY,CAAuC;IAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,oBAAoB;IAaxE;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,SAAS,IAAI,gBAAgB;IAOpC;;;;;OAKG;IACH,MAAM,CAAC,qBAAqB,IAAI,kBAAkB;CAGnD"}
|
package/dist/core/connection.js
CHANGED
|
@@ -1,12 +1,64 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isClientConfig } from './query-builder';
|
|
2
|
+
// Function to synchronously get the appropriate client
|
|
3
|
+
function getClickHouseClientSync() {
|
|
4
|
+
const isDev = process.env.NODE_ENV === 'development';
|
|
5
|
+
const isNode = typeof process !== 'undefined' && process.versions && process.versions.node;
|
|
6
|
+
// In Node.js environment, use Node.js client only
|
|
7
|
+
if (isNode) {
|
|
8
|
+
try {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
10
|
+
const clientNode = require('@clickhouse/client');
|
|
11
|
+
if (isDev) {
|
|
12
|
+
console.log('hypequery: Using @clickhouse/client for Node.js environment');
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
createClient: clientNode.createClient,
|
|
16
|
+
ClickHouseSettings: clientNode.ClickHouseSettings || {}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw new Error('@clickhouse/client is required for Node.js environments.\n\n' +
|
|
21
|
+
'Install with: npm install @clickhouse/client\n\n' +
|
|
22
|
+
'Alternatively, you can provide a client instance directly in the config.client option.');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// For browser environments, require() doesn't work, so we can't auto-detect
|
|
26
|
+
// Users must use manual injection in browser environments
|
|
27
|
+
throw new Error('Unable to auto-detect ClickHouse client in browser environment. ' +
|
|
28
|
+
'Please use manual injection by providing a client instance:\n\n' +
|
|
29
|
+
'```typescript\n' +
|
|
30
|
+
'import { createClient } from \'@clickhouse/client-web\';\n' +
|
|
31
|
+
'const client = createClient({ host: \'http://localhost:8123\' });\n' +
|
|
32
|
+
'ClickHouseConnection.initialize({ host: \'http://localhost:8123\', client });\n' +
|
|
33
|
+
'```\n\n' +
|
|
34
|
+
'This is required because browser environments cannot use require() to load modules.');
|
|
35
|
+
}
|
|
2
36
|
/**
|
|
3
37
|
* The main entry point for connecting to a ClickHouse database.
|
|
4
38
|
* Provides static methods to initialize the connection and retrieve the client.
|
|
5
39
|
*
|
|
40
|
+
* Supports two modes of operation:
|
|
41
|
+
* 1. **Manual injection**: Provide a client instance via `config.client` (required for browser environments)
|
|
42
|
+
* 2. **Auto-detection**: Automatically uses @clickhouse/client for Node.js environments
|
|
43
|
+
*
|
|
6
44
|
* @category Core
|
|
7
45
|
* @example
|
|
8
46
|
* ```typescript
|
|
9
|
-
* //
|
|
47
|
+
* // Method 1: Manual injection (required for browser environments)
|
|
48
|
+
* import { createClient } from '@clickhouse/client-web';
|
|
49
|
+
* const client = createClient({
|
|
50
|
+
* host: 'http://localhost:8123',
|
|
51
|
+
* username: 'default',
|
|
52
|
+
* password: 'password'
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* ClickHouseConnection.initialize({
|
|
56
|
+
* host: 'http://localhost:8123',
|
|
57
|
+
* database: 'my_database',
|
|
58
|
+
* client // Explicitly provide the client
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* // Method 2: Auto-detection (Node.js environments only)
|
|
10
62
|
* ClickHouseConnection.initialize({
|
|
11
63
|
* host: 'http://localhost:8123',
|
|
12
64
|
* username: 'default',
|
|
@@ -21,19 +73,36 @@ import { createClient } from '@clickhouse/client-web';
|
|
|
21
73
|
* format: 'JSONEachRow'
|
|
22
74
|
* });
|
|
23
75
|
* ```
|
|
76
|
+
*
|
|
77
|
+
* @note This library requires one of the following peer dependencies:
|
|
78
|
+
* - @clickhouse/client (for Node.js environments)
|
|
79
|
+
* - @clickhouse/client-web (for browser environments)
|
|
80
|
+
*
|
|
81
|
+
* **Important**: Browser environments require manual injection because `require()` calls don't work in browsers.
|
|
24
82
|
*/
|
|
25
83
|
export class ClickHouseConnection {
|
|
26
84
|
/**
|
|
27
85
|
* Initializes the ClickHouse connection with the provided configuration.
|
|
28
86
|
* This method must be called before any queries can be executed.
|
|
29
87
|
*
|
|
88
|
+
* **Priority order:**
|
|
89
|
+
* 1. If `config.client` is provided, use it directly (manual injection)
|
|
90
|
+
* 2. Otherwise, auto-detect @clickhouse/client for Node.js environments
|
|
91
|
+
*
|
|
92
|
+
* **Note**: Browser environments require manual injection because `require()` calls don't work in browsers.
|
|
93
|
+
*
|
|
30
94
|
* @param config - The connection configuration options
|
|
31
95
|
* @returns The ClickHouseConnection class for method chaining
|
|
32
|
-
* @throws Will throw an error if
|
|
96
|
+
* @throws Will throw an error if no ClickHouse client is available
|
|
33
97
|
*
|
|
34
98
|
* @example
|
|
35
99
|
* ```typescript
|
|
36
|
-
* //
|
|
100
|
+
* // Manual injection (required for browser environments)
|
|
101
|
+
* import { createClient } from '@clickhouse/client-web';
|
|
102
|
+
* const client = createClient({ host: 'http://localhost:8123' });
|
|
103
|
+
* ClickHouseConnection.initialize({ host: 'http://localhost:8123', client });
|
|
104
|
+
*
|
|
105
|
+
* // Auto-detection (Node.js environments only)
|
|
37
106
|
* ClickHouseConnection.initialize({
|
|
38
107
|
* host: 'http://localhost:8123',
|
|
39
108
|
* username: 'default',
|
|
@@ -43,29 +112,14 @@ export class ClickHouseConnection {
|
|
|
43
112
|
* ```
|
|
44
113
|
*/
|
|
45
114
|
static initialize(config) {
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (config.http_headers)
|
|
55
|
-
clientConfig.http_headers = config.http_headers;
|
|
56
|
-
if (config.request_timeout)
|
|
57
|
-
clientConfig.request_timeout = config.request_timeout;
|
|
58
|
-
if (config.compression)
|
|
59
|
-
clientConfig.compression = config.compression;
|
|
60
|
-
if (config.application)
|
|
61
|
-
clientConfig.application = config.application;
|
|
62
|
-
if (config.keep_alive)
|
|
63
|
-
clientConfig.keep_alive = config.keep_alive;
|
|
64
|
-
if (config.log)
|
|
65
|
-
clientConfig.log = config.log;
|
|
66
|
-
if (config.clickhouse_settings)
|
|
67
|
-
clientConfig.clickhouse_settings = config.clickhouse_settings;
|
|
68
|
-
this.instance = createClient(clientConfig);
|
|
115
|
+
// If a client is explicitly provided, use it directly
|
|
116
|
+
if (isClientConfig(config)) {
|
|
117
|
+
this.instance = config.client;
|
|
118
|
+
return ClickHouseConnection;
|
|
119
|
+
}
|
|
120
|
+
// Otherwise, auto-detect the client (we know we have a host-based config)
|
|
121
|
+
this.clientModule = getClickHouseClientSync();
|
|
122
|
+
this.instance = this.clientModule.createClient(config);
|
|
69
123
|
return ClickHouseConnection;
|
|
70
124
|
}
|
|
71
125
|
/**
|
|
@@ -85,8 +139,19 @@ export class ClickHouseConnection {
|
|
|
85
139
|
*/
|
|
86
140
|
static getClient() {
|
|
87
141
|
if (!this.instance) {
|
|
88
|
-
throw new Error('ClickHouse connection not initialized');
|
|
142
|
+
throw new Error('ClickHouse connection not initialized. Call ClickHouseConnection.initialize() first.');
|
|
89
143
|
}
|
|
90
144
|
return this.instance;
|
|
91
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Gets the ClickHouseSettings type from the loaded client module.
|
|
148
|
+
* Only available when using auto-detection (not manual injection).
|
|
149
|
+
*
|
|
150
|
+
* @returns The ClickHouseSettings type or an empty object if not available
|
|
151
|
+
*/
|
|
152
|
+
static getClickHouseSettings() {
|
|
153
|
+
return this.clientModule?.ClickHouseSettings || {};
|
|
154
|
+
}
|
|
92
155
|
}
|
|
156
|
+
ClickHouseConnection.instance = null;
|
|
157
|
+
ClickHouseConnection.clientModule = null;
|
|
@@ -8,17 +8,6 @@ export interface FilterGroup<Schema extends Record<string, Record<string, any>>
|
|
|
8
8
|
direction: 'ASC' | 'DESC';
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
export declare const DateRange: {
|
|
12
|
-
readonly TODAY: "today";
|
|
13
|
-
readonly YESTERDAY: "yesterday";
|
|
14
|
-
readonly LAST_7_DAYS: "last_7_days";
|
|
15
|
-
readonly LAST_30_DAYS: "last_30_days";
|
|
16
|
-
readonly THIS_MONTH: "this_month";
|
|
17
|
-
readonly LAST_MONTH: "last_month";
|
|
18
|
-
readonly THIS_QUARTER: "this_quarter";
|
|
19
|
-
readonly YEAR_TO_DATE: "year_to_date";
|
|
20
|
-
};
|
|
21
|
-
export type DateRangeType = typeof DateRange[keyof typeof DateRange];
|
|
22
11
|
/**
|
|
23
12
|
* A type-safe filter builder supporting both simple conditions and complex nested groups.
|
|
24
13
|
* @template Schema - The full database schema type
|
|
@@ -69,11 +58,6 @@ export declare class CrossFilter<Schema extends {
|
|
|
69
58
|
* Type guard to check if an item is a FilterGroup.
|
|
70
59
|
*/
|
|
71
60
|
private isGroup;
|
|
72
|
-
private addDateCondition;
|
|
73
|
-
addDateRange<K extends keyof Schema[TableName]>(column: K extends keyof Schema[TableName] ? Schema[TableName][K] extends 'Date' | 'DateTime' ? K : never : never, range: DateRangeType): this;
|
|
74
|
-
lastNDays<K extends keyof Schema[TableName]>(column: K extends keyof Schema[TableName] ? Schema[TableName][K] extends 'Date' | 'DateTime' ? K : never : never, days: number): this;
|
|
75
|
-
addComparisonPeriod<K extends keyof Schema[TableName]>(column: K extends keyof Schema[TableName] ? Schema[TableName][K] extends 'Date' | 'DateTime' ? K : never : never, currentRange: [Date, Date]): this;
|
|
76
|
-
addYearOverYear<K extends keyof Schema[TableName]>(column: K extends keyof Schema[TableName] ? Schema[TableName][K] extends 'Date' | 'DateTime' ? K : never : never, currentRange: [Date, Date]): this;
|
|
77
61
|
/**
|
|
78
62
|
* Creates a filter for top N records by a value column
|
|
79
63
|
* @param valueColumn - The column to filter and order by
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cross-filter.d.ts","sourceRoot":"","sources":["../../src/core/cross-filter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAIlB,MAAM,WAAW,WAAW,CAC1B,MAAM,SAAS,MAA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AMf;;;;;OAKG;IACH,IAAI,CAAC,CAAC,SAAS,MAAM,MAAM,CAAC,SAAS,CAAC,EACpC,WAAW,EAAE,CAAC,EACd,CAAC,EAAE,MAAM,EACT,OAAO,GAAE,MAAM,GAAG,KAAc,GAC/B,IAAI;CAmBR"}
|
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
import { FilterValidator } from './validators/filter-validator';
|
|
2
|
-
export const DateRange = {
|
|
3
|
-
TODAY: 'today',
|
|
4
|
-
YESTERDAY: 'yesterday',
|
|
5
|
-
LAST_7_DAYS: 'last_7_days',
|
|
6
|
-
LAST_30_DAYS: 'last_30_days',
|
|
7
|
-
THIS_MONTH: 'this_month',
|
|
8
|
-
LAST_MONTH: 'last_month',
|
|
9
|
-
THIS_QUARTER: 'this_quarter',
|
|
10
|
-
YEAR_TO_DATE: 'year_to_date'
|
|
11
|
-
};
|
|
12
2
|
/**
|
|
13
3
|
* A type-safe filter builder supporting both simple conditions and complex nested groups.
|
|
14
4
|
* @template Schema - The full database schema type
|
|
@@ -120,78 +110,6 @@ export class CrossFilter {
|
|
|
120
110
|
isGroup(item) {
|
|
121
111
|
return typeof item.conditions !== 'undefined';
|
|
122
112
|
}
|
|
123
|
-
addDateCondition(column, value) {
|
|
124
|
-
this.rootGroup.conditions.push({
|
|
125
|
-
column,
|
|
126
|
-
operator: 'between',
|
|
127
|
-
value: [value[0].toISOString(), value[1].toISOString()]
|
|
128
|
-
});
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
addDateRange(column, range) {
|
|
132
|
-
const now = new Date();
|
|
133
|
-
let start;
|
|
134
|
-
let end;
|
|
135
|
-
switch (range) {
|
|
136
|
-
case 'today':
|
|
137
|
-
start = new Date(now.setHours(0, 0, 0, 0));
|
|
138
|
-
end = new Date(now.setHours(23, 59, 59, 999));
|
|
139
|
-
break;
|
|
140
|
-
case 'yesterday':
|
|
141
|
-
start = new Date(now.setDate(now.getDate() - 1));
|
|
142
|
-
start.setHours(0, 0, 0, 0);
|
|
143
|
-
end = new Date(start);
|
|
144
|
-
end.setHours(23, 59, 59, 999);
|
|
145
|
-
break;
|
|
146
|
-
case 'last_7_days':
|
|
147
|
-
end = new Date(now);
|
|
148
|
-
start = new Date(now.setDate(now.getDate() - 7));
|
|
149
|
-
break;
|
|
150
|
-
case 'last_30_days':
|
|
151
|
-
end = new Date(now);
|
|
152
|
-
start = new Date(now.setDate(now.getDate() - 30));
|
|
153
|
-
break;
|
|
154
|
-
case 'this_month':
|
|
155
|
-
start = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
156
|
-
end = new Date(now.getFullYear(), now.getMonth() + 1, 0);
|
|
157
|
-
break;
|
|
158
|
-
case 'last_month':
|
|
159
|
-
start = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
|
160
|
-
end = new Date(now.getFullYear(), now.getMonth(), 0);
|
|
161
|
-
break;
|
|
162
|
-
case 'this_quarter':
|
|
163
|
-
const quarter = Math.floor(now.getMonth() / 3);
|
|
164
|
-
start = new Date(now.getFullYear(), quarter * 3, 1);
|
|
165
|
-
end = new Date(now.getFullYear(), (quarter + 1) * 3, 0);
|
|
166
|
-
break;
|
|
167
|
-
case 'year_to_date':
|
|
168
|
-
start = new Date(now.getFullYear(), 0, 1);
|
|
169
|
-
end = new Date(now);
|
|
170
|
-
break;
|
|
171
|
-
default:
|
|
172
|
-
throw new Error(`Unsupported date range: ${range}`);
|
|
173
|
-
}
|
|
174
|
-
return this.addDateCondition(column, [start, end]);
|
|
175
|
-
}
|
|
176
|
-
lastNDays(column, days) {
|
|
177
|
-
const end = new Date();
|
|
178
|
-
const start = new Date();
|
|
179
|
-
start.setDate(start.getDate() - days);
|
|
180
|
-
return this.addDateCondition(column, [start, end]);
|
|
181
|
-
}
|
|
182
|
-
addComparisonPeriod(column, currentRange) {
|
|
183
|
-
const periodLength = currentRange[1].getTime() - currentRange[0].getTime();
|
|
184
|
-
const previousStart = new Date(currentRange[0].getTime() - periodLength);
|
|
185
|
-
const previousEnd = new Date(currentRange[1].getTime() - periodLength);
|
|
186
|
-
return this.addDateCondition(column, [previousStart, previousEnd]);
|
|
187
|
-
}
|
|
188
|
-
addYearOverYear(column, currentRange) {
|
|
189
|
-
const previousStart = new Date(currentRange[0]);
|
|
190
|
-
previousStart.setFullYear(previousStart.getFullYear() - 1);
|
|
191
|
-
const previousEnd = new Date(currentRange[1]);
|
|
192
|
-
previousEnd.setFullYear(previousEnd.getFullYear() - 1);
|
|
193
|
-
return this.addDateCondition(column, [previousStart, previousEnd]);
|
|
194
|
-
}
|
|
195
113
|
/**
|
|
196
114
|
* Creates a filter for top N records by a value column
|
|
197
115
|
* @param valueColumn - The column to filter and order by
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { QueryBuilder } from '../query-builder';
|
|
2
2
|
import { ColumnType, TableColumn } from '../../types';
|
|
3
|
-
import { ClickHouseSettings } from '@clickhouse/client-
|
|
3
|
+
import { ClickHouseSettings } from '@clickhouse/client-common';
|
|
4
4
|
export declare class AnalyticsFeature<Schema extends {
|
|
5
5
|
[tableName: string]: {
|
|
6
6
|
[columnName: string]: ColumnType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../../src/core/features/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../../src/core/features/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAE9D,qBAAa,gBAAgB,CAC3B,MAAM,SAAS;IAAE,CAAC,SAAS,EAAE,MAAM,GAAG;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAAA;KAAE,CAAA;CAAE,EAC5E,CAAC,EACD,SAAS,SAAS,OAAO,GAAG,KAAK,EACjC,YAAY,GAAG,EAAE,EACjB,SAAS,GAAG,CAAC;IAED,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,CAAC;IAExF,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,MAAM;;;;;;;;;;;;;;;;;;IAS/D,eAAe,CACb,MAAM,EAAE,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,EACrC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,mBAAmB,GAAG,iBAAiB,GAAG,eAAe,GAAG,cAAc,GAAG,eAAe,GAAG,gBAAgB,GAAG,kBAAkB,GAAG,eAAe;;;;;;;;;;;;;;;;;;IAiBhK,WAAW,CAAC,IAAI,EAAE,kBAAkB;;;;;;;;;;;;;;;;;;CAQrC"}
|
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
import { CrossFilter } from './cross-filter';
|
|
2
2
|
import { ColumnType, FilterOperator, OrderDirection, TableColumn, AggregationType, QueryConfig, OperatorValueMap, InferColumnType, PaginationOptions, PaginatedResult } from '../types';
|
|
3
|
-
import { ClickHouseSettings } from '@clickhouse/client-web';
|
|
4
3
|
import { SQLFormatter } from './formatters/sql-formatter';
|
|
5
4
|
import { JoinRelationships, JoinPathOptions } from './join-relationships';
|
|
6
5
|
import { SqlExpression } from './utils/sql-expressions';
|
|
6
|
+
import type { ClickHouseSettings, BaseClickHouseClientConfigOptions } from '@clickhouse/client-common';
|
|
7
|
+
import type { ClickHouseClient as NodeClickHouseClient } from '@clickhouse/client';
|
|
8
|
+
import type { ClickHouseClient as WebClickHouseClient } from '@clickhouse/client-web';
|
|
9
|
+
type ClickHouseClient = NodeClickHouseClient | WebClickHouseClient;
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for host-based connections.
|
|
12
|
+
*/
|
|
13
|
+
export interface ClickHouseHostConfig extends BaseClickHouseClientConfigOptions {
|
|
14
|
+
/** The ClickHouse server host URL. */
|
|
15
|
+
host: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Configuration for client-based connections.
|
|
19
|
+
*/
|
|
20
|
+
export interface ClickHouseClientConfig extends BaseClickHouseClientConfigOptions {
|
|
21
|
+
/** Pre-configured ClickHouse client instance. */
|
|
22
|
+
client: ClickHouseClient;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Configuration options for ClickHouse connections.
|
|
26
|
+
* Either provide a client instance OR connection details, but not both.
|
|
27
|
+
*/
|
|
28
|
+
export type ClickHouseConfig = ClickHouseHostConfig | ClickHouseClientConfig;
|
|
29
|
+
/**
|
|
30
|
+
* Type guard to check if a config is a host-based configuration.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isHostConfig(config: ClickHouseConfig): config is ClickHouseHostConfig;
|
|
33
|
+
/**
|
|
34
|
+
* Type guard to check if a config is a client-based configuration.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isClientConfig(config: ClickHouseConfig): config is ClickHouseClientConfig;
|
|
7
37
|
/**
|
|
8
38
|
* A type-safe query builder for ClickHouse databases.
|
|
9
39
|
* @template Schema - The full database schema
|
|
@@ -199,24 +229,8 @@ export declare function createQueryBuilder<Schema extends {
|
|
|
199
229
|
[K in keyof Schema]: {
|
|
200
230
|
[columnName: string]: ColumnType;
|
|
201
231
|
};
|
|
202
|
-
}>(config: {
|
|
203
|
-
host: string;
|
|
204
|
-
username?: string;
|
|
205
|
-
password?: string;
|
|
206
|
-
database?: string;
|
|
207
|
-
http_headers?: Record<string, string>;
|
|
208
|
-
request_timeout?: number;
|
|
209
|
-
compression?: {
|
|
210
|
-
response?: boolean;
|
|
211
|
-
request?: boolean;
|
|
212
|
-
};
|
|
213
|
-
application?: string;
|
|
214
|
-
keep_alive?: {
|
|
215
|
-
enabled: boolean;
|
|
216
|
-
};
|
|
217
|
-
log?: any;
|
|
218
|
-
clickhouse_settings?: ClickHouseSettings;
|
|
219
|
-
}): {
|
|
232
|
+
}>(config: ClickHouseConfig): {
|
|
220
233
|
table<TableName extends keyof Schema>(tableName: TableName): QueryBuilder<Schema, Schema[TableName], false, {}>;
|
|
221
234
|
};
|
|
235
|
+
export {};
|
|
222
236
|
//# sourceMappingURL=query-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../../src/core/query-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACL,UAAU,EACV,cAAc,EACd,cAAc,EACd,WAAW,EACX,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,eAAe,EAChB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../../src/core/query-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACL,UAAU,EACV,cAAc,EACd,cAAc,EACd,WAAW,EACX,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,eAAe,EAChB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAS1D,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iCAAiC,EAAE,M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WlH"}
|
|
@@ -9,6 +9,18 @@ import { QueryModifiersFeature } from './features/query-modifiers';
|
|
|
9
9
|
import { FilterValidator } from './validators/filter-validator';
|
|
10
10
|
import { PaginationFeature } from './features/pagination';
|
|
11
11
|
import { CrossFilteringFeature } from './features/cross-filtering';
|
|
12
|
+
/**
|
|
13
|
+
* Type guard to check if a config is a host-based configuration.
|
|
14
|
+
*/
|
|
15
|
+
export function isHostConfig(config) {
|
|
16
|
+
return 'host' in config && !('client' in config);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Type guard to check if a config is a client-based configuration.
|
|
20
|
+
*/
|
|
21
|
+
export function isClientConfig(config) {
|
|
22
|
+
return 'client' in config && !('host' in config);
|
|
23
|
+
}
|
|
12
24
|
/**
|
|
13
25
|
* A type-safe query builder for ClickHouse databases.
|
|
14
26
|
* @template Schema - The full database schema
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const initializeTestConnection: () => Promise<{
|
|
2
2
|
table<TableName extends never>(tableName: TableName): import("../../query-builder").QueryBuilder<{}, {}[TableName], false, {}, {}[TableName]>;
|
|
3
3
|
}>;
|
|
4
|
-
export declare const ensureConnectionInitialized: () => import("@clickhouse/client-web
|
|
4
|
+
export declare const ensureConnectionInitialized: () => import("@clickhouse/client").ClickHouseClient | import("@clickhouse/client-web").ClickHouseClient;
|
|
5
5
|
export declare const isDockerAvailable: () => Promise<boolean>;
|
|
6
6
|
export declare const isDockerComposeAvailable: () => Promise<boolean>;
|
|
7
7
|
export declare const isContainerRunning: (containerName: string) => Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../../src/core/tests/integration/setup.ts"],"names":[],"mappings":"AA6CA,eAAO,MAAM,wBAAwB;;EAyBpC,CAAC;AAGF,eAAO,MAAM,2BAA2B,
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../../src/core/tests/integration/setup.ts"],"names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,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;CACJ;AAGD,eAAO,MAAM,SAAS,EAAE,cAoBvB,CAAC;AAGF,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,IAAI,CAuFtD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export { createQueryBuilder } from './core/query-builder.js';
|
|
1
|
+
export { createQueryBuilder, QueryBuilder } from './core/query-builder.js';
|
|
2
2
|
export { ClickHouseConnection } from './core/connection.js';
|
|
3
3
|
export { JoinRelationships } from './core/join-relationships.js';
|
|
4
|
+
export type { ClickHouseConfig, ClickHouseHostConfig, ClickHouseClientConfig } from './core/query-builder.js';
|
|
5
|
+
export { isHostConfig, isClientConfig } from './core/query-builder.js';
|
|
4
6
|
export type { TableSchema, QueryConfig, ColumnType, WhereExpression, GroupByExpression, TableRecord, DatabaseSchema, PaginatedResult, PageInfo, PaginationOptions } from './types/base';
|
|
5
7
|
export type { JoinPath, JoinPathOptions } from './core/join-relationships.js';
|
|
6
8
|
export { CrossFilter } from './core/cross-filter.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACvE,YAAY,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,eAAe,EACf,QAAQ,EACR,iBAAiB,EAClB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EACL,GAAG,EACH,KAAK,EACL,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,QAAQ,EACR,qBAAqB,EACtB,MAAM,iCAAiC,CAAC;AACzC,YAAY,EACV,aAAa,EACb,iBAAiB,EAClB,MAAM,iCAAiC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypequery/clickhouse",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "ClickHouse typescript query builder",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -35,11 +35,25 @@
|
|
|
35
35
|
"README-CLI.md"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@clickhouse/client-web": "^0.2.0",
|
|
39
38
|
"dotenv": "^16.0.0"
|
|
40
39
|
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@clickhouse/client": "^0.2.0 || ^1.0.0",
|
|
42
|
+
"@clickhouse/client-web": "^0.2.0 || ^1.0.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"@clickhouse/client": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
48
|
+
"@clickhouse/client-web": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
41
52
|
"devDependencies": {
|
|
42
53
|
"@babel/plugin-transform-modules-commonjs": "^7.26.3",
|
|
54
|
+
"@clickhouse/client": "^1.11.2",
|
|
55
|
+
"@clickhouse/client-common": "^1.11.2",
|
|
56
|
+
"@clickhouse/client-web": "^1.11.2",
|
|
43
57
|
"@semantic-release/changelog": "^6.0.3",
|
|
44
58
|
"@semantic-release/commit-analyzer": "^11.1.0",
|
|
45
59
|
"@semantic-release/git": "^10.0.1",
|