@hypequery/clickhouse 1.1.4 → 1.2.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/dist/cli/generate-types.js +1 -1
- package/dist/core/connection.d.ts.map +1 -1
- package/dist/core/connection.js +1 -1
- package/dist/core/cross-filter.js +1 -1
- package/dist/core/features/executor.js +3 -3
- package/dist/core/features/filtering.d.ts +1 -1
- package/dist/core/features/filtering.d.ts.map +1 -1
- package/dist/core/features/filtering.js +30 -2
- package/dist/core/formatters/sql-formatter.d.ts.map +1 -1
- package/dist/core/formatters/sql-formatter.js +37 -0
- package/dist/core/join-relationships.d.ts +1 -1
- package/dist/core/join-relationships.d.ts.map +1 -1
- package/dist/core/query-builder.d.ts +38 -5
- package/dist/core/query-builder.d.ts.map +1 -1
- package/dist/core/query-builder.js +48 -25
- package/dist/core/tests/integration/setup.d.ts +1 -1
- package/dist/core/tests/integration/setup.d.ts.map +1 -1
- package/dist/core/tests/integration/setup.js +2 -2
- 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 +4 -5
- package/dist/core/tests/test-utils.d.ts.map +1 -1
- package/dist/core/tests/test-utils.js +6 -2
- package/dist/core/validators/filter-validator.js +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/types/clickhouse-types.d.ts +2 -3
- package/dist/types/clickhouse-types.d.ts.map +1 -1
- package/dist/types/filters.d.ts +18 -2
- package/dist/types/filters.d.ts.map +1 -1
- package/package.json +4 -3
- package/README.md +0 -253
|
@@ -148,7 +148,7 @@ export interface IntrospectedSchema {`;
|
|
|
148
148
|
* Usage example:
|
|
149
149
|
*
|
|
150
150
|
* import { createQueryBuilder } from '@hypequery/clickhouse';
|
|
151
|
-
* import { IntrospectedSchema } from './path-to-this-file';
|
|
151
|
+
* import { IntrospectedSchema } from './path-to-this-file.js';
|
|
152
152
|
*
|
|
153
153
|
* // Create a type-safe query builder
|
|
154
154
|
* const db = createQueryBuilder<IntrospectedSchema>();
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { FilterValidator } from './validators/filter-validator';
|
|
1
|
+
import { FilterValidator } from './validators/filter-validator.js';
|
|
2
2
|
/**
|
|
3
3
|
* A type-safe filter builder supporting both simple conditions and complex nested groups.
|
|
4
4
|
* @template Schema - The full database schema type
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ClickHouseConnection } from '../connection';
|
|
2
|
-
import { substituteParameters } from '../utils';
|
|
3
|
-
import { logger } from '../utils/logger';
|
|
1
|
+
import { ClickHouseConnection } from '../connection.js';
|
|
2
|
+
import { substituteParameters } from '../utils.js';
|
|
3
|
+
import { logger } from '../utils/logger.js';
|
|
4
4
|
export class ExecutorFeature {
|
|
5
5
|
constructor(builder) {
|
|
6
6
|
this.builder = builder;
|
|
@@ -7,7 +7,7 @@ export declare class FilteringFeature<Schema extends {
|
|
|
7
7
|
}, T, HasSelect extends boolean = false, Aggregations = {}, OriginalT = T> {
|
|
8
8
|
private builder;
|
|
9
9
|
constructor(builder: QueryBuilder<Schema, T, HasSelect, Aggregations, OriginalT>);
|
|
10
|
-
addCondition<K extends keyof OriginalT | TableColumn<Schema>>(conjunction: 'AND' | 'OR', column: K, operator: FilterOperator, value: any): {
|
|
10
|
+
addCondition<K extends keyof OriginalT | TableColumn<Schema>>(conjunction: 'AND' | 'OR', column: K | K[], operator: FilterOperator, value: any): {
|
|
11
11
|
where: import("../../types").WhereCondition[];
|
|
12
12
|
parameters: any[];
|
|
13
13
|
select?: (string | keyof T)[] | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../../../src/core/features/filtering.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,MA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AAE,cAAc,EACxB,KAAK,EAAE,GAAG;;;;;;;;;;;;;;;;;;IA4DZ;;;OAGG;IACH,eAAe;;;;;;;;;;;;;;;;;;IAkBf;;;OAGG;IACH,iBAAiB;;;;;;;;;;;;;;;;;;IAkBjB;;;OAGG;IACH,aAAa;;;;;;;;;;;;;;;;;;CAiBd"}
|
|
@@ -6,16 +6,44 @@ export class FilteringFeature {
|
|
|
6
6
|
const config = this.builder.getConfig();
|
|
7
7
|
const where = config.where || [];
|
|
8
8
|
const parameters = config.parameters || [];
|
|
9
|
+
// Handle tuple columns
|
|
10
|
+
const columnString = Array.isArray(column)
|
|
11
|
+
? `(${column.map(String).join(', ')})`
|
|
12
|
+
: String(column);
|
|
9
13
|
where.push({
|
|
10
|
-
column:
|
|
14
|
+
column: columnString,
|
|
11
15
|
operator,
|
|
12
16
|
value,
|
|
13
17
|
conjunction,
|
|
14
18
|
type: 'condition'
|
|
15
19
|
});
|
|
16
|
-
|
|
20
|
+
// Handle different parameter types based on operator
|
|
21
|
+
if (operator === 'in' || operator === 'notIn' || operator === 'globalIn' || operator === 'globalNotIn') {
|
|
22
|
+
if (!Array.isArray(value)) {
|
|
23
|
+
throw new Error(`Expected an array for ${operator} operator, but got ${typeof value}`);
|
|
24
|
+
}
|
|
17
25
|
parameters.push(...value);
|
|
18
26
|
}
|
|
27
|
+
else if (operator === 'inTuple' || operator === 'globalInTuple') {
|
|
28
|
+
if (!Array.isArray(value)) {
|
|
29
|
+
throw new Error(`Expected an array of tuples for ${operator} operator, but got ${typeof value}`);
|
|
30
|
+
}
|
|
31
|
+
value.forEach((tuple) => {
|
|
32
|
+
parameters.push(...tuple);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else if (operator === 'inSubquery' || operator === 'globalInSubquery') {
|
|
36
|
+
if (typeof value !== 'string') {
|
|
37
|
+
throw new Error(`Expected a string (subquery) for ${operator} operator, but got ${typeof value}`);
|
|
38
|
+
}
|
|
39
|
+
// No parameters
|
|
40
|
+
}
|
|
41
|
+
else if (operator === 'inTable' || operator === 'globalInTable') {
|
|
42
|
+
if (typeof value !== 'string') {
|
|
43
|
+
throw new Error(`Expected a string (table name) for ${operator} operator, but got ${typeof value}`);
|
|
44
|
+
}
|
|
45
|
+
// No parameters
|
|
46
|
+
}
|
|
19
47
|
else if (operator === 'between') {
|
|
20
48
|
parameters.push(value[0], value[1]);
|
|
21
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-formatter.d.ts","sourceRoot":"","sources":["../../../src/core/formatters/sql-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAE1D,qBAAa,YAAY;IACvB,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,MAAM;IAMnD,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,MAAM;IASpD,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,MAAM;
|
|
1
|
+
{"version":3,"file":"sql-formatter.d.ts","sourceRoot":"","sources":["../../../src/core/formatters/sql-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAE1D,qBAAa,YAAY;IACvB,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,MAAM;IAMnD,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,MAAM;IASpD,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,MAAM;IA6FlD,OAAO,CAAC,cAAc;IActB,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,MAAM;CAUnD"}
|
|
@@ -36,6 +36,7 @@ export class SQLFormatter {
|
|
|
36
36
|
const prefix = index === 0 || afterGroupStart ? '' : ` ${conjunction} `;
|
|
37
37
|
// Reset the afterGroupStart flag
|
|
38
38
|
afterGroupStart = false;
|
|
39
|
+
// Handle IN operators
|
|
39
40
|
if (operator === 'in' || operator === 'notIn') {
|
|
40
41
|
if (!Array.isArray(value)) {
|
|
41
42
|
throw new Error(`Expected an array for ${operator} operator, but got ${typeof value}`);
|
|
@@ -46,6 +47,42 @@ export class SQLFormatter {
|
|
|
46
47
|
const placeholders = value.map(() => '?').join(', ');
|
|
47
48
|
return `${prefix}${column} ${operator === 'in' ? 'IN' : 'NOT IN'} (${placeholders})`.trim();
|
|
48
49
|
}
|
|
50
|
+
// Handle GLOBAL IN operators
|
|
51
|
+
else if (operator === 'globalIn' || operator === 'globalNotIn') {
|
|
52
|
+
if (!Array.isArray(value)) {
|
|
53
|
+
throw new Error(`Expected an array for ${operator} operator, but got ${typeof value}`);
|
|
54
|
+
}
|
|
55
|
+
if (value.length === 0) {
|
|
56
|
+
return `${prefix}1 = 0`;
|
|
57
|
+
}
|
|
58
|
+
const placeholders = value.map(() => '?').join(', ');
|
|
59
|
+
return `${prefix}${column} ${operator === 'globalIn' ? 'GLOBAL IN' : 'GLOBAL NOT IN'} (${placeholders})`.trim();
|
|
60
|
+
}
|
|
61
|
+
// Handle subquery IN operators
|
|
62
|
+
else if (operator === 'inSubquery' || operator === 'globalInSubquery') {
|
|
63
|
+
if (typeof value !== 'string') {
|
|
64
|
+
throw new Error(`Expected a string (subquery) for ${operator} operator, but got ${typeof value}`);
|
|
65
|
+
}
|
|
66
|
+
return `${prefix}${column} ${operator === 'inSubquery' ? 'IN' : 'GLOBAL IN'} (${value})`.trim();
|
|
67
|
+
}
|
|
68
|
+
// Handle table reference IN operators
|
|
69
|
+
else if (operator === 'inTable' || operator === 'globalInTable') {
|
|
70
|
+
if (typeof value !== 'string') {
|
|
71
|
+
throw new Error(`Expected a string (table name) for ${operator} operator, but got ${typeof value}`);
|
|
72
|
+
}
|
|
73
|
+
return `${prefix}${column} ${operator === 'inTable' ? 'IN' : 'GLOBAL IN'} ${value}`.trim();
|
|
74
|
+
}
|
|
75
|
+
// Handle tuple IN operators
|
|
76
|
+
else if (operator === 'inTuple' || operator === 'globalInTuple') {
|
|
77
|
+
if (!Array.isArray(value)) {
|
|
78
|
+
throw new Error(`Expected an array of tuples for ${operator} operator, but got ${typeof value}`);
|
|
79
|
+
}
|
|
80
|
+
if (value.length === 0) {
|
|
81
|
+
return `${prefix}1 = 0`;
|
|
82
|
+
}
|
|
83
|
+
const placeholders = value.map(() => '(?, ?)').join(', ');
|
|
84
|
+
return `${prefix}${column} ${operator === 'inTuple' ? 'IN' : 'GLOBAL IN'} (${placeholders})`.trim();
|
|
85
|
+
}
|
|
49
86
|
else if (operator === 'between') {
|
|
50
87
|
return `${prefix}${column} BETWEEN ? AND ?`.trim();
|
|
51
88
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"join-relationships.d.ts","sourceRoot":"","sources":["../../src/core/join-relationships.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEhD,MAAM,WAAW,QAAQ,CAAC,MAAM;IAC9B,IAAI,EAAE,MAAM,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED,qBAAa,iBAAiB,CAAC,MAAM,SAAS;
|
|
1
|
+
{"version":3,"file":"join-relationships.d.ts","sourceRoot":"","sources":["../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GpC"}
|
|
@@ -7,6 +7,13 @@ import type { ClickHouseSettings, BaseClickHouseClientConfigOptions } from '@cli
|
|
|
7
7
|
import type { ClickHouseClient as NodeClickHouseClient } from '@clickhouse/client';
|
|
8
8
|
import type { ClickHouseClient as WebClickHouseClient } from '@clickhouse/client-web';
|
|
9
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
|
+
}
|
|
10
17
|
/**
|
|
11
18
|
* Configuration for client-based connections.
|
|
12
19
|
*/
|
|
@@ -18,11 +25,11 @@ export interface ClickHouseClientConfig extends BaseClickHouseClientConfigOption
|
|
|
18
25
|
* Configuration options for ClickHouse connections.
|
|
19
26
|
* Either provide a client instance OR connection details, but not both.
|
|
20
27
|
*/
|
|
21
|
-
export type ClickHouseConfig =
|
|
28
|
+
export type ClickHouseConfig = ClickHouseHostConfig | ClickHouseClientConfig;
|
|
22
29
|
/**
|
|
23
30
|
* Type guard to check if a config is a host-based configuration.
|
|
24
31
|
*/
|
|
25
|
-
export declare function isHostConfig(config: ClickHouseConfig): config is
|
|
32
|
+
export declare function isHostConfig(config: ClickHouseConfig): config is ClickHouseHostConfig;
|
|
26
33
|
/**
|
|
27
34
|
* Type guard to check if a config is a client-based configuration.
|
|
28
35
|
*/
|
|
@@ -35,7 +42,7 @@ export declare function isClientConfig(config: ClickHouseConfig): config is Clic
|
|
|
35
42
|
* @template Aggregations - The type of any aggregation functions applied
|
|
36
43
|
*/
|
|
37
44
|
export declare class QueryBuilder<Schema extends {
|
|
38
|
-
[
|
|
45
|
+
[K in keyof Schema]: {
|
|
39
46
|
[columnName: string]: ColumnType;
|
|
40
47
|
};
|
|
41
48
|
}, T, HasSelect extends boolean = false, Aggregations = {}, OriginalT = T> {
|
|
@@ -127,8 +134,34 @@ export declare class QueryBuilder<Schema extends {
|
|
|
127
134
|
* builder.where('age', 'gt', 18)
|
|
128
135
|
* ```
|
|
129
136
|
*/
|
|
130
|
-
where<K extends keyof OriginalT | TableColumn<Schema>, Op extends keyof OperatorValueMap<any>>(
|
|
137
|
+
where<K extends keyof OriginalT | TableColumn<Schema>, Op extends keyof OperatorValueMap<any, Schema>>(columnOrColumns: K | K[], operator: Op, value: K extends keyof OriginalT ? OperatorValueMap<OriginalT[K] extends ColumnType ? InferColumnType<OriginalT[K]> : never, Schema>[Op] : any): this;
|
|
138
|
+
/**
|
|
139
|
+
* Adds a WHERE clause for tuple IN operations.
|
|
140
|
+
* @template K - The column keys type
|
|
141
|
+
* @param {K[]} columns - The columns to filter on (for tuple operations)
|
|
142
|
+
* @param {'inTuple' | 'globalInTuple'} operator - The tuple IN operator
|
|
143
|
+
* @param {any} value - The array of tuples to compare against
|
|
144
|
+
* @returns {this} The current QueryBuilder instance
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* builder.where(['counter_id', 'user_id'], 'inTuple', [[34, 123], [101500, 456]])
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
where<K extends keyof OriginalT | TableColumn<Schema>>(columns: K[], operator: 'inTuple' | 'globalInTuple', value: any): this;
|
|
131
151
|
orWhere<K extends keyof OriginalT | TableColumn<Schema>>(column: K, operator: FilterOperator, value: any): this;
|
|
152
|
+
/**
|
|
153
|
+
* Adds an OR WHERE clause for tuple IN operations.
|
|
154
|
+
* @template K - The column keys type
|
|
155
|
+
* @param {K[]} columns - The columns to filter on (for tuple operations)
|
|
156
|
+
* @param {'inTuple' | 'globalInTuple'} operator - The tuple IN operator
|
|
157
|
+
* @param {any} value - The array of tuples to compare against
|
|
158
|
+
* @returns {this} The current QueryBuilder instance
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* builder.orWhere(['counter_id', 'user_id'], 'inTuple', [[34, 123], [101500, 456]])
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
orWhere<K extends keyof OriginalT | TableColumn<Schema>>(columns: K[], operator: 'inTuple' | 'globalInTuple', value: any): this;
|
|
132
165
|
/**
|
|
133
166
|
* Creates a parenthesized group of WHERE conditions joined with AND/OR operators.
|
|
134
167
|
* @param {Function} callback - Function that builds the conditions within the group
|
|
@@ -209,7 +242,7 @@ export declare class QueryBuilder<Schema extends {
|
|
|
209
242
|
*/
|
|
210
243
|
iteratePages(pageSize: number): AsyncGenerator<PaginatedResult<T>>;
|
|
211
244
|
static setJoinRelationships<S extends {
|
|
212
|
-
[
|
|
245
|
+
[K in keyof S]: {
|
|
213
246
|
[columnName: string]: ColumnType;
|
|
214
247
|
};
|
|
215
248
|
}>(relationships: JoinRelationships<S>): void;
|
|
@@ -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,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,MAAM,2BAA2B,CAAC;AACvG,OAAO,KAAK,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,gBAAgB,IAAI,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAGtF,KAAK,gBAAgB,GAAG,o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EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,CAAC;IAO9D,SAAS;IAIT;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAI1E;;OAEG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAI9D;;OAEG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAIlE,MAAM,CAAC,oBAAoB,CAAC,CAAC,SAAS;SAAG,CAAC,IAAI,MAAM,CAAC,GAAG;YAAE,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAAA;SAAE;KAAE,EAC5F,aAAa,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAClC,IAAI;IAIP;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI;CA4B5D;AAED,wBAAgB,kBAAkB,CAAC,MAAM,SAAS;KAC/C,CAAC,IAAI,MAAM,MAAM,GAAG;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAAA;KAAE;CAC1D,EACC,MAAM,EAAE,gBAAgB;UAKhB,SAAS,SAAS,MAAM,MAAM,aAAa,SAAS,GAAG,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;EAWlH"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ClickHouseConnection } from './connection';
|
|
2
|
-
import { SQLFormatter } from './formatters/sql-formatter';
|
|
3
|
-
import { AggregationFeature } from './features/aggregations';
|
|
4
|
-
import { JoinFeature } from './features/joins';
|
|
5
|
-
import { FilteringFeature } from './features/filtering';
|
|
6
|
-
import { AnalyticsFeature } from './features/analytics';
|
|
7
|
-
import { ExecutorFeature } from './features/executor';
|
|
8
|
-
import { QueryModifiersFeature } from './features/query-modifiers';
|
|
9
|
-
import { FilterValidator } from './validators/filter-validator';
|
|
10
|
-
import { PaginationFeature } from './features/pagination';
|
|
11
|
-
import { CrossFilteringFeature } from './features/cross-filtering';
|
|
1
|
+
import { ClickHouseConnection } from './connection.js';
|
|
2
|
+
import { SQLFormatter } from './formatters/sql-formatter.js';
|
|
3
|
+
import { AggregationFeature } from './features/aggregations.js';
|
|
4
|
+
import { JoinFeature } from './features/joins.js';
|
|
5
|
+
import { FilteringFeature } from './features/filtering.js';
|
|
6
|
+
import { AnalyticsFeature } from './features/analytics.js';
|
|
7
|
+
import { ExecutorFeature } from './features/executor.js';
|
|
8
|
+
import { QueryModifiersFeature } from './features/query-modifiers.js';
|
|
9
|
+
import { FilterValidator } from './validators/filter-validator.js';
|
|
10
|
+
import { PaginationFeature } from './features/pagination.js';
|
|
11
|
+
import { CrossFilteringFeature } from './features/cross-filtering.js';
|
|
12
12
|
/**
|
|
13
13
|
* Type guard to check if a config is a host-based configuration.
|
|
14
14
|
*/
|
|
@@ -210,29 +210,52 @@ export class QueryBuilder {
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
validateFilterValue(column, operator, value) {
|
|
213
|
+
// Handle tuple columns
|
|
214
|
+
if (Array.isArray(column)) {
|
|
215
|
+
// For tuple operations, we don't validate individual column types
|
|
216
|
+
// as they might be cross-table references
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
// Skip validation for advanced IN operators - they handle their own validation
|
|
220
|
+
const advancedInOperators = [
|
|
221
|
+
'globalIn', 'globalNotIn', 'inSubquery', 'globalInSubquery',
|
|
222
|
+
'inTable', 'globalInTable', 'inTuple', 'globalInTuple'
|
|
223
|
+
];
|
|
224
|
+
if (advancedInOperators.includes(operator)) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
213
227
|
if (FilterValidator.validateJoinedColumn(String(column)))
|
|
214
228
|
return;
|
|
215
229
|
const columnType = this.schema.columns[column];
|
|
216
230
|
FilterValidator.validateFilterCondition({ column: String(column), operator, value }, columnType);
|
|
217
231
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
*/
|
|
230
|
-
where(column, operator, value) {
|
|
232
|
+
where(columnOrColumns, operator, value) {
|
|
233
|
+
// Handle tuple operations
|
|
234
|
+
if (Array.isArray(columnOrColumns) && (operator === 'inTuple' || operator === 'globalInTuple')) {
|
|
235
|
+
// For tuple operations, we need to handle the column array specially
|
|
236
|
+
const columns = columnOrColumns;
|
|
237
|
+
this.validateFilterValue(columns, operator, value);
|
|
238
|
+
this.config = this.filtering.addCondition('AND', columns, operator, value);
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
// Handle regular operations
|
|
242
|
+
const column = columnOrColumns;
|
|
231
243
|
this.validateFilterValue(column, operator, value);
|
|
232
244
|
this.config = this.filtering.addCondition('AND', column, operator, value);
|
|
233
245
|
return this;
|
|
234
246
|
}
|
|
235
|
-
orWhere(
|
|
247
|
+
orWhere(columnOrColumns, operator, value) {
|
|
248
|
+
// Handle tuple operations
|
|
249
|
+
if (Array.isArray(columnOrColumns) && (operator === 'inTuple' || operator === 'globalInTuple')) {
|
|
250
|
+
// For tuple operations, we need to handle the column array specially
|
|
251
|
+
const columns = columnOrColumns;
|
|
252
|
+
this.validateFilterValue(columns, operator, value);
|
|
253
|
+
this.config = this.filtering.addCondition('OR', columns, operator, value);
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
// Handle regular operations
|
|
257
|
+
const column = columnOrColumns;
|
|
258
|
+
this.validateFilterValue(column, operator, value);
|
|
236
259
|
this.config = this.filtering.addCondition('OR', column, operator, value);
|
|
237
260
|
return this;
|
|
238
261
|
}
|
|
@@ -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
|
|
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":[],"mappings":"AA6CA,eAAO,MAAM,wBAAwB;;EAyBpC,CAAC;AAGF,eAAO,MAAM,2BAA2B,yGAevC,CAAC;AAGF,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,OAAO,CAOzD,CAAC;AAGF,eAAO,MAAM,wBAAwB,QAAa,OAAO,CAAC,OAAO,CAahE,CAAC;AAGF,eAAO,MAAM,kBAAkB,GAAU,eAAe,MAAM,KAAG,OAAO,CAAC,OAAO,CAO/E,CAAC;AAGF,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,OAAO,CAQzD,CAAC;AAGF,eAAO,MAAM,wBAAwB,QAAa,OAAO,CAAC,IAAI,CAwC7D,CAAC;AAGF,eAAO,MAAM,iBAAiB,GAC5B,oBAAgB,EAChB,sBAAoB,KACnB,OAAO,CAAC,IAAI,CAad,CAAC;AAGF,eAAO,MAAM,uBAAuB,QAAa,OAAO,CAAC,IAAI,CA0B5D,CAAC;AAGF,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,KAAK,CAAC;QAChB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,OAAO,CAAC;KACpB,CAAC,CAAC;IACH,KAAK,EAAE,KAAK,CAAC;QACX,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;IACH,MAAM,EAAE,KAAK,CAAC;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,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"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
|
-
import { ClickHouseConnection } from '../../connection';
|
|
3
|
+
import { ClickHouseConnection } from '../../connection.js';
|
|
4
4
|
import { exec } from 'child_process';
|
|
5
5
|
import { promisify } from 'util';
|
|
6
|
-
import { logger as hypeQueryLogger } from '../../utils/logger';
|
|
6
|
+
import { logger as hypeQueryLogger } from '../../utils/logger.js';
|
|
7
7
|
// Disable the hypequery logger to prevent "logs after tests" errors
|
|
8
8
|
// This must be done early in the setup, before any queries run
|
|
9
9
|
hypeQueryLogger.configure({ enabled: false });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common initialization for all integration tests
|
|
3
|
+
* Import this at the beginning of each test file to ensure consistent setup
|
|
4
|
+
*/
|
|
5
|
+
export declare const skipIntegrationTests: () => boolean;
|
|
6
|
+
export declare const initializeForTest: () => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=test-initializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-initializer.d.ts","sourceRoot":"","sources":["../../../../src/core/tests/integration/test-initializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,eAAO,MAAM,oBAAoB,eAEhC,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,IAAI,CAqBtD,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common initialization for all integration tests
|
|
3
|
+
* Import this at the beginning of each test file to ensure consistent setup
|
|
4
|
+
*/
|
|
5
|
+
import { startClickHouseContainer, waitForClickHouse, ensureConnectionInitialized, setupTestDatabase } from './setup.js';
|
|
6
|
+
export const skipIntegrationTests = () => {
|
|
7
|
+
return process.env.SKIP_INTEGRATION_TESTS === 'true' || process.env.CI === 'true';
|
|
8
|
+
};
|
|
9
|
+
export const initializeForTest = async () => {
|
|
10
|
+
if (skipIntegrationTests()) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
// Initialize the connection
|
|
15
|
+
ensureConnectionInitialized();
|
|
16
|
+
// Make sure container is running
|
|
17
|
+
await startClickHouseContainer();
|
|
18
|
+
// Wait for ClickHouse to be ready
|
|
19
|
+
await waitForClickHouse();
|
|
20
|
+
// Set up the test database
|
|
21
|
+
await setupTestDatabase();
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error('Failed to initialize test environment:', error);
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
// Automatically initialize when this module is imported
|
|
29
|
+
initializeForTest().catch(error => {
|
|
30
|
+
console.error('Test initialization failed:', error);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { QueryBuilder } from '../query-builder';
|
|
2
|
-
type ColumnType = 'Int32' | 'String' | 'Float64' | 'Date' | 'UInt8';
|
|
3
2
|
export type TestTableSchema = {
|
|
4
3
|
id: 'Int32';
|
|
5
4
|
name: 'String';
|
|
@@ -9,6 +8,10 @@ export type TestTableSchema = {
|
|
|
9
8
|
active: 'UInt8';
|
|
10
9
|
created_by: 'Int32';
|
|
11
10
|
updated_by: 'Int32';
|
|
11
|
+
status: 'String';
|
|
12
|
+
brand: 'String';
|
|
13
|
+
total: 'Int32';
|
|
14
|
+
priority: 'String';
|
|
12
15
|
};
|
|
13
16
|
export type UsersSchema = {
|
|
14
17
|
id: 'Int32';
|
|
@@ -19,12 +22,8 @@ export type UsersSchema = {
|
|
|
19
22
|
export interface TestSchema {
|
|
20
23
|
test_table: TestTableSchema;
|
|
21
24
|
users: UsersSchema;
|
|
22
|
-
[tableName: string]: {
|
|
23
|
-
[columnName: string]: ColumnType;
|
|
24
|
-
};
|
|
25
25
|
}
|
|
26
26
|
export declare const TEST_SCHEMAS: TestSchema;
|
|
27
27
|
export declare function setupUsersBuilder(): QueryBuilder<TestSchema, TestSchema['users'], false, {}, TestSchema['users']>;
|
|
28
28
|
export declare function setupTestBuilder(): QueryBuilder<TestSchema, TestSchema['test_table'], false, {}, TestSchema['test_table']>;
|
|
29
|
-
export {};
|
|
30
29
|
//# sourceMappingURL=test-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tests/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tests/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,SAAS,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,QAAQ,CAAC;IACjB,KAAK,EAAE,QAAQ,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,OAAO,CAAC;IACZ,SAAS,EAAE,QAAQ,CAAC;IACpB,KAAK,EAAE,QAAQ,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAGF,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,eAAe,CAAC;IAC5B,KAAK,EAAE,WAAW,CAAC;CACpB;AAGD,eAAO,MAAM,YAAY,EAAE,UAqB1B,CAAC;AAEF,wBAAgB,iBAAiB,IAAI,YAAY,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CASjH;AAED,wBAAgB,gBAAgB,IAAI,YAAY,CAAC,UAAU,EAAE,UAAU,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC,CAS1H"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { QueryBuilder } from '../query-builder';
|
|
1
|
+
import { QueryBuilder } from '../query-builder.js';
|
|
2
2
|
// Test data
|
|
3
3
|
export const TEST_SCHEMAS = {
|
|
4
4
|
test_table: {
|
|
@@ -9,7 +9,11 @@ export const TEST_SCHEMAS = {
|
|
|
9
9
|
category: 'String',
|
|
10
10
|
active: 'UInt8',
|
|
11
11
|
created_by: 'Int32',
|
|
12
|
-
updated_by: 'Int32'
|
|
12
|
+
updated_by: 'Int32',
|
|
13
|
+
status: 'String',
|
|
14
|
+
brand: 'String',
|
|
15
|
+
total: 'Int32',
|
|
16
|
+
priority: 'String',
|
|
13
17
|
},
|
|
14
18
|
users: {
|
|
15
19
|
id: 'Int32',
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
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, ClickHouseClientConfig } from './core/query-builder.js';
|
|
4
|
+
export type { ClickHouseConfig, ClickHouseHostConfig, ClickHouseClientConfig } from './core/query-builder.js';
|
|
5
5
|
export { isHostConfig, isClientConfig } from './core/query-builder.js';
|
|
6
|
-
export type { ClickHouseSettings, BaseClickHouseClientConfigOptions } from '@clickhouse/client-common';
|
|
7
|
-
export type { ClickHouseClient } from '@clickhouse/client';
|
|
8
|
-
export type { ClickHouseClient as WebClickHouseClient } from '@clickhouse/client-web';
|
|
9
6
|
export type { TableSchema, QueryConfig, ColumnType, WhereExpression, GroupByExpression, TableRecord, DatabaseSchema, PaginatedResult, PageInfo, PaginationOptions } from './types/base';
|
|
10
7
|
export type { JoinPath, JoinPathOptions } from './core/join-relationships.js';
|
|
11
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,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,sBAAsB,EACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACvE,YAAY,
|
|
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"}
|
|
@@ -3,12 +3,11 @@ export type ClickHouseFloat = 'Float32' | 'Float64';
|
|
|
3
3
|
export type ClickHouseDecimal = 'Decimal32' | 'Decimal64' | 'Decimal128' | 'Decimal256' | `Decimal(${number}, ${number})`;
|
|
4
4
|
export type ClickHouseDateTime = 'Date' | 'Date32' | 'DateTime' | `DateTime('${string}')` | `DateTime64(${number})` | `DateTime64(${number}, '${string}')`;
|
|
5
5
|
export type ClickHouseString = 'String' | `FixedString(${number})` | 'UUID';
|
|
6
|
-
export type ClickHouseEnum = `Enum8(${string})` | `Enum16(${string})`;
|
|
7
6
|
export type ClickHouseArray = `Array(${ClickHouseBaseType})`;
|
|
8
7
|
export type ClickHouseNullable = `Nullable(${ClickHouseBaseType})`;
|
|
9
8
|
export type ClickHouseLowCardinality = `LowCardinality(${ClickHouseString})`;
|
|
10
9
|
export type ClickHouseMap = `Map(${ClickHouseBaseType}, ${ClickHouseBaseType})`;
|
|
11
|
-
export type ClickHouseBaseType = ClickHouseInteger | ClickHouseFloat | ClickHouseDecimal | ClickHouseDateTime | ClickHouseString
|
|
10
|
+
export type ClickHouseBaseType = ClickHouseInteger | ClickHouseFloat | ClickHouseDecimal | ClickHouseDateTime | ClickHouseString;
|
|
12
11
|
export type ClickHouseType = ClickHouseBaseType | ClickHouseArray | ClickHouseNullable | ClickHouseLowCardinality | ClickHouseMap;
|
|
13
|
-
export type InferClickHouseType<T extends ClickHouseType> = T extends ClickHouseInteger ? number : T extends ClickHouseFloat ? number : T extends ClickHouseDecimal ? number : T extends ClickHouseDateTime ? Date : T extends ClickHouseString ? string : T extends
|
|
12
|
+
export type InferClickHouseType<T extends ClickHouseType> = T extends ClickHouseInteger ? number : T extends ClickHouseFloat ? number : T extends ClickHouseDecimal ? number : T extends ClickHouseDateTime ? Date : T extends ClickHouseString ? string : T extends `Array(${infer U extends ClickHouseBaseType})` ? Array<InferClickHouseType<U>> : T extends `Nullable(${infer U extends ClickHouseBaseType})` ? InferClickHouseType<U> | null : T extends `LowCardinality(${infer U extends ClickHouseString})` ? InferClickHouseType<U> : T extends `Map(${infer K extends ClickHouseBaseType}, ${infer V extends ClickHouseBaseType})` ? Map<InferClickHouseType<K>, InferClickHouseType<V>> : never;
|
|
14
13
|
//# sourceMappingURL=clickhouse-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clickhouse-types.d.ts","sourceRoot":"","sources":["../../src/types/clickhouse-types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,iBAAiB,GACzB,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAC1D,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAErE,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,SAAS,CAAC;AAEpD,MAAM,MAAM,iBAAiB,GACzB,WAAW,GAAG,WAAW,GAAG,YAAY,GAAG,YAAY,GACvD,WAAW,MAAM,KAAK,MAAM,GAAG,CAAC;AAGpC,MAAM,MAAM,kBAAkB,GAC1B,MAAM,GAAG,QAAQ,GACjB,UAAU,GACV,aAAa,MAAM,IAAI,GACvB,cAAc,MAAM,GAAG,GACvB,cAAc,MAAM,MAAM,MAAM,IAAI,CAAC;AAGzC,MAAM,MAAM,gBAAgB,GACxB,QAAQ,GACR,eAAe,MAAM,GAAG,GACxB,MAAM,CAAC;AAGX,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"clickhouse-types.d.ts","sourceRoot":"","sources":["../../src/types/clickhouse-types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,iBAAiB,GACzB,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAC1D,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAErE,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,SAAS,CAAC;AAEpD,MAAM,MAAM,iBAAiB,GACzB,WAAW,GAAG,WAAW,GAAG,YAAY,GAAG,YAAY,GACvD,WAAW,MAAM,KAAK,MAAM,GAAG,CA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C,GACxF,CAAC,SAAS,OAAO,MAAM,CAAC,SAAS,kBAAkB,KAAK,MAAM,CAAC,SAAS,kBAAkB,GAAG,GAC7F,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC,GACnD,KAAK,CAAC"}
|
package/dist/types/filters.d.ts
CHANGED
|
@@ -12,9 +12,17 @@ export type FilterCondition<T> = {
|
|
|
12
12
|
between: [FilterValue<T>, FilterValue<T>] | [string, string];
|
|
13
13
|
like: T extends string ? string : never;
|
|
14
14
|
notLike: T extends string ? string : never;
|
|
15
|
+
globalIn: FilterValue<T>[];
|
|
16
|
+
globalNotIn: FilterValue<T>[];
|
|
17
|
+
inSubquery: string;
|
|
18
|
+
globalInSubquery: string;
|
|
19
|
+
inTable: string;
|
|
20
|
+
globalInTable: string;
|
|
21
|
+
inTuple: [FilterValue<T>, FilterValue<T>][];
|
|
22
|
+
globalInTuple: [FilterValue<T>, FilterValue<T>][];
|
|
15
23
|
};
|
|
16
|
-
export type FilterValueType<T, Op extends FilterOperator> = Op extends 'in' | 'notIn' ? T extends (infer U)[] ? U[] : T[] : Op extends 'between' ? [T, T] | [string, string] : T;
|
|
17
|
-
export type OperatorValueMap<T> = {
|
|
24
|
+
export type FilterValueType<T, Op extends FilterOperator, Schema = any> = Op extends 'in' | 'notIn' | 'globalIn' | 'globalNotIn' ? T extends (infer U)[] ? U[] : T[] : Op extends 'between' ? [T, T] | [string, string] : Op extends 'inSubquery' | 'globalInSubquery' ? string : Op extends 'inTable' | 'globalInTable' ? keyof Schema : Op extends 'inTuple' | 'globalInTuple' ? [T, T][] : T;
|
|
25
|
+
export type OperatorValueMap<T, Schema = any> = {
|
|
18
26
|
'eq': T | string;
|
|
19
27
|
'neq': T | string;
|
|
20
28
|
'gt': T extends string | number | Date ? T | string : never;
|
|
@@ -26,6 +34,14 @@ export type OperatorValueMap<T> = {
|
|
|
26
34
|
'between': [T | string, T | string] | [string, string];
|
|
27
35
|
'like': T extends string ? string : never;
|
|
28
36
|
'notLike': T extends string ? string : never;
|
|
37
|
+
'globalIn': (T | string)[];
|
|
38
|
+
'globalNotIn': (T | string)[];
|
|
39
|
+
'inSubquery': string;
|
|
40
|
+
'globalInSubquery': string;
|
|
41
|
+
'inTable': keyof Schema;
|
|
42
|
+
'globalInTable': keyof Schema;
|
|
43
|
+
'inTuple': [T | string, T | string][];
|
|
44
|
+
'globalInTuple': [T | string, T | string][];
|
|
29
45
|
};
|
|
30
46
|
export type FilterOperator = keyof OperatorValueMap<any>;
|
|
31
47
|
export interface FilterConditionInput<T = any, Schema extends Record<string, Record<string, any>> = any, OriginalT extends Record<string, any> = any> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filters.d.ts","sourceRoot":"","sources":["../../src/types/filters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,MAAM,MAAM,WAAW,CAAC,CAAC,IACvB,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,MAAM,GAC9B,CAAC,SAAS,MAAM,GAAG,MAAM,GACzB,CAAC,SAAS,MAAM,GAAG,MAAM,GACzB,CAAC,SAAS,OAAO,GAAG,OAAO,GAC3B,KAAK,CAAC;AAER,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;IAC/B,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACnB,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACpB,EAAE,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;IACrD,GAAG,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;IACtD,EAAE,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;IACrD,GAAG,EAAE,CA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CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,MAAM,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,MAAM,CAAC;IAC9B,SAAS,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC;IACtC,eAAe,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,gBAAgB,CAAC,GAAG,CAAC,CAAC;AAEzD,MAAM,WAAW,oBAAoB,CACnC,CAAC,GAAG,GAAG,EACP,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,EACxD,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG;IAE3C,MAAM,EAAE,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IAC9C,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,CAAC,CAAC;IACT,WAAW,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;CAC5B"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypequery/clickhouse",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "ClickHouse typescript query builder",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"license": "Apache-2.0",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "npm run build:main && npm run build:cli && npm run fix-typedefs && npm run verify-build || npm run diagnose-ci",
|
|
10
|
+
"build": "npm run build:main && npm run build:cli && npm run fix-typedefs && npm run fix-esm-imports && npm run verify-build || npm run diagnose-ci",
|
|
11
11
|
"build:main": "tsc --project tsconfig.json",
|
|
12
12
|
"build:cli": "node scripts/ensure-core-files.js && node scripts/handle-cli-files.js",
|
|
13
|
-
"build:ci": "npm run build:main && node scripts/ensure-core-files.js && node scripts/handle-cli-files.js && npm run fix-typedefs && npm run verify-build || npm run diagnose-ci",
|
|
13
|
+
"build:ci": "npm run build:main && node scripts/ensure-core-files.js && node scripts/handle-cli-files.js && npm run fix-typedefs && npm run fix-esm-imports && npm run verify-build || npm run diagnose-ci",
|
|
14
14
|
"fix-typedefs": "node scripts/fix-typedefs.js",
|
|
15
|
+
"fix-esm-imports": "node scripts/fix-esm-imports.js",
|
|
15
16
|
"verify-build": "node scripts/verify-build.js",
|
|
16
17
|
"diagnose-ci": "node scripts/diagnose-ci.js",
|
|
17
18
|
"dev": "tsc --watch",
|
package/README.md
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<h1>@hypequery/clickhouse</h1>
|
|
3
|
-
<p>A typescript-first library for building type-safe dashboards with ClickHouse</p>
|
|
4
|
-
|
|
5
|
-
[](https://github.com/hypequery/hypequery/blob/main/LICENSE)
|
|
6
|
-
[](https://badge.fury.io/js/@hypequery%2Fclickhouse)
|
|
7
|
-
[](https://github.com/hypequery/hypequery/stargazers)
|
|
8
|
-
</div>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Overview
|
|
12
|
-
|
|
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.
|
|
14
|
-
|
|
15
|
-
## Features
|
|
16
|
-
|
|
17
|
-
- 🎯 **Type-Safe**: Full TypeScript support with types from your ClickHouse schema
|
|
18
|
-
- 🚀 **Performant**: Built for real-time analytics with optimized query generation
|
|
19
|
-
- 🔍 **Cross Filtering**: Powerful cross-filtering capabilities for interactive dashboards
|
|
20
|
-
- 🛠️ **Developer Friendly**: Fluent API design for an intuitive development experience
|
|
21
|
-
- 📱 **Platform Agnostic**: Works in both Node.js and browser environments
|
|
22
|
-
- 🔄 **Schema Generation**: CLI tool to generate TypeScript types from your ClickHouse schema
|
|
23
|
-
|
|
24
|
-
## Installation
|
|
25
|
-
|
|
26
|
-
This library requires one of the following ClickHouse clients as a peer dependency:
|
|
27
|
-
|
|
28
|
-
### For Node.js environments
|
|
29
|
-
```bash
|
|
30
|
-
npm install @hypequery/clickhouse @clickhouse/client
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### For browser/universal environments
|
|
34
|
-
```bash
|
|
35
|
-
npm install @hypequery/clickhouse @clickhouse/client-web
|
|
36
|
-
```
|
|
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
|
-
|
|
42
|
-
## Quick Start
|
|
43
|
-
|
|
44
|
-
### Node.js Environments
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
import { createQueryBuilder } from '@hypequery/clickhouse';
|
|
48
|
-
import type { IntrospectedSchema } from './generated-schema';
|
|
49
|
-
|
|
50
|
-
// Initialize the query builder
|
|
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({
|
|
77
|
-
host: 'your-clickhouse-host',
|
|
78
|
-
username: 'default',
|
|
79
|
-
password: '',
|
|
80
|
-
database: 'default'
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// Initialize the query builder with the client
|
|
84
|
-
const db = createQueryBuilder<IntrospectedSchema>({
|
|
85
|
-
client // Explicitly provide the client
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// Build and execute a query
|
|
89
|
-
const results = await db
|
|
90
|
-
.table('trips')
|
|
91
|
-
.select(['pickup_datetime', 'dropoff_datetime', 'total_amount'])
|
|
92
|
-
.where('total_amount', '>', 50)
|
|
93
|
-
.orderBy('pickup_datetime', 'DESC')
|
|
94
|
-
.limit(10)
|
|
95
|
-
.execute();
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## Schema Generation
|
|
99
|
-
|
|
100
|
-
hypequery provides a CLI tool to generate TypeScript types from your ClickHouse schema:
|
|
101
|
-
|
|
102
|
-
```bash
|
|
103
|
-
# Install globally (optional)
|
|
104
|
-
npm install -g @hypequery/clickhouse
|
|
105
|
-
|
|
106
|
-
# Generate schema types
|
|
107
|
-
npx hypequery-generate-types --host your-clickhouse-host --database your-database
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
This creates a `generated-schema.ts` file that you can import in your application:
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
import { createQueryBuilder } from '@hypequery/clickhouse';
|
|
114
|
-
import type { IntrospectedSchema } from './generated-schema';
|
|
115
|
-
|
|
116
|
-
const db = createQueryBuilder<IntrospectedSchema>({
|
|
117
|
-
// connection details
|
|
118
|
-
});
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
## Core Features
|
|
122
|
-
|
|
123
|
-
### Type-Safe Queries
|
|
124
|
-
|
|
125
|
-
hypequery provides full TypeScript support, ensuring your queries are type-safe:
|
|
126
|
-
|
|
127
|
-
```typescript
|
|
128
|
-
// Column names are type-checked
|
|
129
|
-
const query = db.table('trips')
|
|
130
|
-
.select(['pickup_datetime', 'total_amount'])
|
|
131
|
-
.where('total_amount', 'gt', 50)
|
|
132
|
-
.execute();
|
|
133
|
-
|
|
134
|
-
// Type error if column doesn't exist
|
|
135
|
-
db.table('trips').select(['non_existent_column']); // TypeScript error
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### Cross Filtering
|
|
139
|
-
|
|
140
|
-
Implement interactive dashboards with cross-filtering support:
|
|
141
|
-
|
|
142
|
-
```typescript
|
|
143
|
-
import { CrossFilter } from '@hypequery/clickhouse';
|
|
144
|
-
|
|
145
|
-
// Create a filter
|
|
146
|
-
const filter = new CrossFilter()
|
|
147
|
-
.add({
|
|
148
|
-
column: 'pickup_datetime',
|
|
149
|
-
operator: 'gte',
|
|
150
|
-
value: '2024-01-01'
|
|
151
|
-
})
|
|
152
|
-
.add({
|
|
153
|
-
column: 'total_amount',
|
|
154
|
-
operator: 'gt',
|
|
155
|
-
value: 20
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// Apply to multiple queries
|
|
159
|
-
const query1 = db.table('trips')
|
|
160
|
-
.applyCrossFilters(filter)
|
|
161
|
-
.execute();
|
|
162
|
-
|
|
163
|
-
const query2 = db.table('drivers')
|
|
164
|
-
.applyCrossFilters(filter)
|
|
165
|
-
.execute();
|
|
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', 'gte', '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
|
-
```
|
|
188
|
-
|
|
189
|
-
|
|
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
|
|
195
|
-
|
|
196
|
-
#### 2. Auto-Detection with Fallback (Node.js Environments Only)
|
|
197
|
-
|
|
198
|
-
```typescript
|
|
199
|
-
const db = createQueryBuilder<IntrospectedSchema>({
|
|
200
|
-
host: 'your-clickhouse-host',
|
|
201
|
-
username: 'default',
|
|
202
|
-
password: '',
|
|
203
|
-
database: 'default'
|
|
204
|
-
});
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
## Versioning and Release Channels
|
|
209
|
-
|
|
210
|
-
hypequery follows semantic versioning and provides multiple release channels:
|
|
211
|
-
|
|
212
|
-
- **Latest**: Stable releases (`npm install @hypequery/clickhouse`)
|
|
213
|
-
- **Beta**: Pre-release versions (`npm install @hypequery/clickhouse@beta`)
|
|
214
|
-
|
|
215
|
-
## Documentation
|
|
216
|
-
|
|
217
|
-
For detailed documentation and examples, visit our [documentation site](https://hypequery.com/docs).
|
|
218
|
-
|
|
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)
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
## Troubleshooting
|
|
227
|
-
|
|
228
|
-
### Common Issues
|
|
229
|
-
|
|
230
|
-
- **Connection Errors**: Ensure your ClickHouse server is running and accessible
|
|
231
|
-
- **CORS Issues**: Use a proxy server for browser environments
|
|
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.
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
## License
|
|
240
|
-
|
|
241
|
-
This project is licensed under the Apache-2.0 License - see the [LICENSE](LICENSE) file for details.
|
|
242
|
-
|
|
243
|
-
## Support
|
|
244
|
-
|
|
245
|
-
- 📚 [Documentation](https://hypequery.com/docs)
|
|
246
|
-
- 🐛 [Issue Tracker](https://github.com/hypequery/hypequery/issues)
|
|
247
|
-
- 💬 [Discussions](https://github.com/hypequery/hypequery/discussions)
|
|
248
|
-
|
|
249
|
-
---
|
|
250
|
-
|
|
251
|
-
<div align="center">
|
|
252
|
-
<sub>Built with ❤️ by the hypequery team</sub>
|
|
253
|
-
</div>
|