@hypequery/clickhouse 0.2.1 → 0.2.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-CLI.md +1 -1
- package/dist/cli/bin.js +129 -37
- package/dist/cli/generate-types.js +104 -15
- package/dist/core/connection.d.ts +112 -0
- package/dist/core/connection.d.ts.map +1 -1
- package/dist/core/connection.js +148 -25
- package/dist/core/cross-filter.d.ts +69 -0
- package/dist/core/cross-filter.d.ts.map +1 -1
- package/dist/core/cross-filter.js +1 -83
- package/dist/core/features/aggregations.d.ts +102 -0
- package/dist/core/features/analytics.d.ts +66 -0
- package/dist/core/features/analytics.d.ts.map +1 -1
- package/dist/core/features/cross-filtering.d.ts +31 -0
- package/dist/core/features/cross-filtering.d.ts.map +1 -0
- package/dist/core/features/cross-filtering.js +123 -0
- package/dist/core/features/executor.d.ts +19 -0
- package/dist/core/features/executor.js +3 -3
- package/dist/core/features/filtering.d.ts +95 -0
- package/dist/core/features/filtering.d.ts.map +1 -1
- package/dist/core/features/filtering.js +89 -3
- package/dist/core/features/joins.d.ts +29 -0
- package/dist/core/features/pagination.d.ts +23 -0
- package/dist/core/features/query-modifiers.d.ts +119 -0
- package/dist/core/formatters/sql-formatter.d.ts +9 -0
- package/dist/core/formatters/sql-formatter.d.ts.map +1 -1
- package/dist/core/formatters/sql-formatter.js +61 -5
- package/dist/core/join-relationships.d.ts +50 -0
- package/dist/core/join-relationships.d.ts.map +1 -1
- package/dist/core/query-builder.d.ts +258 -0
- package/dist/core/query-builder.d.ts.map +1 -1
- package/dist/core/query-builder.js +88 -27
- package/dist/core/tests/index.d.ts +2 -0
- package/dist/core/tests/integration/pagination-test-tbc.d.ts +2 -0
- package/dist/core/tests/integration/pagination-test-tbc.d.ts.map +1 -0
- package/dist/core/tests/integration/pagination-test-tbc.js +189 -0
- package/dist/core/tests/integration/setup.d.ts +40 -0
- package/dist/core/tests/integration/setup.d.ts.map +1 -1
- package/dist/core/tests/integration/setup.js +279 -238
- package/dist/core/tests/integration/test-config.d.ts +15 -0
- package/dist/core/tests/integration/test-config.d.ts.map +1 -0
- package/dist/core/tests/integration/test-config.js +15 -0
- package/dist/core/tests/integration/test-initializer.d.ts +7 -0
- package/dist/core/tests/integration/test-initializer.d.ts.map +1 -0
- package/dist/core/tests/integration/test-initializer.js +32 -0
- package/dist/core/tests/test-utils.d.ts +29 -0
- package/dist/core/tests/test-utils.d.ts.map +1 -1
- package/dist/core/tests/test-utils.js +6 -2
- package/dist/core/utils/logger.d.ts +37 -0
- package/dist/core/utils/logger.js +6 -6
- package/dist/core/utils/sql-expressions.d.ts +63 -0
- package/dist/core/utils/sql-expressions.d.ts.map +1 -1
- package/dist/core/utils/sql-expressions.js +9 -5
- package/dist/core/utils.d.ts +3 -0
- package/dist/core/validators/filter-validator.d.ts +8 -0
- package/dist/core/validators/filter-validator.js +1 -1
- package/dist/core/validators/value-validator.d.ts +6 -0
- package/dist/formatters/index.d.ts +1 -0
- package/dist/index.d.ts +12 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -2
- package/dist/types/base.d.ts +77 -0
- package/dist/types/base.d.ts.map +1 -1
- package/dist/types/clickhouse-types.d.ts +13 -0
- package/dist/types/clickhouse-types.d.ts.map +1 -1
- package/dist/types/filters.d.ts +53 -0
- package/dist/types/filters.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -0
- package/package.json +36 -13
- package/README.md +0 -276
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ColumnType, JoinType } from '../types';
|
|
2
|
+
export interface JoinPath<Schema> {
|
|
3
|
+
from: keyof Schema;
|
|
4
|
+
to: keyof Schema;
|
|
5
|
+
leftColumn: string;
|
|
6
|
+
rightColumn: string;
|
|
7
|
+
type?: JoinType;
|
|
8
|
+
alias?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface JoinPathOptions {
|
|
11
|
+
type?: JoinType;
|
|
12
|
+
alias?: string;
|
|
13
|
+
context?: Record<string, any>;
|
|
14
|
+
}
|
|
15
|
+
export declare class JoinRelationships<Schema extends {
|
|
16
|
+
[K in keyof Schema]: {
|
|
17
|
+
[columnName: string]: ColumnType;
|
|
18
|
+
};
|
|
19
|
+
}> {
|
|
20
|
+
private paths;
|
|
21
|
+
/**
|
|
22
|
+
* Define a single join relationship
|
|
23
|
+
*/
|
|
24
|
+
define(name: string, path: JoinPath<Schema>): void;
|
|
25
|
+
/**
|
|
26
|
+
* Define a chain of join relationships
|
|
27
|
+
*/
|
|
28
|
+
defineChain(name: string, paths: JoinPath<Schema>[]): void;
|
|
29
|
+
/**
|
|
30
|
+
* Get a join relationship by name
|
|
31
|
+
*/
|
|
32
|
+
get(name: string): JoinPath<Schema> | JoinPath<Schema>[] | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a join relationship exists
|
|
35
|
+
*/
|
|
36
|
+
has(name: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Remove a join relationship
|
|
39
|
+
*/
|
|
40
|
+
remove(name: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Clear all join relationships
|
|
43
|
+
*/
|
|
44
|
+
clear(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Get all defined relationship names
|
|
47
|
+
*/
|
|
48
|
+
getDefinedRelationships(): string[];
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=join-relationships.d.ts.map
|
|
@@ -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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,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,EAAE,GAAG,SAAS;IAIpE;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI7B;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,uBAAuB,IAAI,MAAM,EAAE;CAGpC"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { CrossFilter } from './cross-filter';
|
|
2
|
+
import { ColumnType, FilterOperator, OrderDirection, TableColumn, AggregationType, QueryConfig, OperatorValueMap, InferColumnType, PaginationOptions, PaginatedResult } from '../types';
|
|
3
|
+
import { SQLFormatter } from './formatters/sql-formatter';
|
|
4
|
+
import { JoinRelationships, JoinPathOptions } from './join-relationships';
|
|
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 client-based configuration.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isClientConfig(config: ClickHouseConfig): config is ClickHouseClientConfig;
|
|
33
|
+
/**
|
|
34
|
+
* A type-safe query builder for ClickHouse databases.
|
|
35
|
+
* @template Schema - The full database schema
|
|
36
|
+
* @template T - The schema type of the current table
|
|
37
|
+
* @template HasSelect - Whether a SELECT clause has been applied
|
|
38
|
+
* @template Aggregations - The type of any aggregation functions applied
|
|
39
|
+
*/
|
|
40
|
+
export declare class QueryBuilder<Schema extends {
|
|
41
|
+
[K in keyof Schema]: {
|
|
42
|
+
[columnName: string]: ColumnType;
|
|
43
|
+
};
|
|
44
|
+
}, T, HasSelect extends boolean = false, Aggregations = {}, OriginalT = T> {
|
|
45
|
+
private static relationships;
|
|
46
|
+
private config;
|
|
47
|
+
private tableName;
|
|
48
|
+
private schema;
|
|
49
|
+
private originalSchema;
|
|
50
|
+
private formatter;
|
|
51
|
+
private aggregations;
|
|
52
|
+
private joins;
|
|
53
|
+
private filtering;
|
|
54
|
+
private analytics;
|
|
55
|
+
private executor;
|
|
56
|
+
private modifiers;
|
|
57
|
+
private pagination;
|
|
58
|
+
private crossFiltering;
|
|
59
|
+
constructor(tableName: string, schema: {
|
|
60
|
+
name: string;
|
|
61
|
+
columns: T;
|
|
62
|
+
}, originalSchema: Schema);
|
|
63
|
+
debug(): this;
|
|
64
|
+
clone(): QueryBuilder<Schema, T, HasSelect, Aggregations, OriginalT>;
|
|
65
|
+
withCTE(alias: string, subquery: QueryBuilder<any, any> | string): this;
|
|
66
|
+
/**
|
|
67
|
+
* Groups results by a time interval using a specified ClickHouse function.
|
|
68
|
+
*
|
|
69
|
+
* @param column - The column containing the date or timestamp.
|
|
70
|
+
* @param interval - The interval value. For example, "1 day" or "15 minute".
|
|
71
|
+
* This is only used when the method is 'toStartOfInterval'.
|
|
72
|
+
* @param method - The time bucketing function to use.
|
|
73
|
+
* Defaults to 'toStartOfInterval'.
|
|
74
|
+
* Other valid values include 'toStartOfMinute', 'toStartOfHour',
|
|
75
|
+
* 'toStartOfDay', 'toStartOfWeek', 'toStartOfMonth', 'toStartOfQuarter', and 'toStartOfYear'.
|
|
76
|
+
* @returns The current QueryBuilder instance.
|
|
77
|
+
*/
|
|
78
|
+
groupByTimeInterval(column: keyof T | TableColumn<Schema>, interval: string, method?: 'toStartOfInterval' | 'toStartOfMinute' | 'toStartOfHour' | 'toStartOfDay' | 'toStartOfWeek' | 'toStartOfMonth' | 'toStartOfQuarter' | 'toStartOfYear'): this;
|
|
79
|
+
raw(sql: string): this;
|
|
80
|
+
settings(opts: ClickHouseSettings): this;
|
|
81
|
+
/**
|
|
82
|
+
* Applies a set of cross filters to the current query.
|
|
83
|
+
* All filter conditions from the provided CrossFilter are added to the query.
|
|
84
|
+
* @param crossFilter - An instance of CrossFilter containing shared filter conditions.
|
|
85
|
+
* @returns The current QueryBuilder instance.
|
|
86
|
+
*/
|
|
87
|
+
applyCrossFilters(crossFilter: CrossFilter<Schema, keyof Schema>): this;
|
|
88
|
+
/**
|
|
89
|
+
* Selects specific columns from the table.
|
|
90
|
+
* @template K - The keys/columns to select
|
|
91
|
+
* @param {K[]} columns - Array of column names to select
|
|
92
|
+
* @returns {QueryBuilder} A new QueryBuilder instance with updated types
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* builder.select(['id', 'name'])
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
select<K extends keyof T | TableColumn<Schema> | SqlExpression>(columns: K[]): QueryBuilder<Schema, {
|
|
99
|
+
[P in Extract<K, keyof T | TableColumn<Schema>> as P extends `${string}.${infer C}` ? C : P]: P extends keyof T ? (T[P] extends "String" ? string : T[P] extends "Date" ? Date : T[P] extends "Float64" | "Int32" | "Int64" ? number : never) : string;
|
|
100
|
+
}, true, Aggregations, OriginalT>;
|
|
101
|
+
sum<Column extends keyof OriginalT, Alias extends string = `${Column & string}_sum`>(column: Column, alias?: Alias): QueryBuilder<Schema, AggregationType<T, Aggregations, Column, Alias, 'sum', HasSelect>, true, {}, OriginalT>;
|
|
102
|
+
count<Column extends keyof OriginalT, Alias extends string = `${Column & string}_count`>(column: Column, alias?: Alias): QueryBuilder<Schema, AggregationType<T, Aggregations, Column, Alias, 'count', HasSelect>, true, {}, OriginalT>;
|
|
103
|
+
avg<Column extends keyof OriginalT, Alias extends string = `${Column & string}_avg`>(column: Column, alias?: Alias): QueryBuilder<Schema, AggregationType<T, Aggregations, Column, Alias, 'avg', HasSelect>, true, {}, OriginalT>;
|
|
104
|
+
min<Column extends keyof OriginalT, Alias extends string = `${Column & string}_min`>(column: Column, alias?: Alias): QueryBuilder<Schema, AggregationType<T, Aggregations, Column, Alias, 'min', HasSelect>, true, {}, OriginalT>;
|
|
105
|
+
max<Column extends keyof OriginalT, Alias extends string = `${Column & string}_max`>(column: Column, alias?: Alias): QueryBuilder<Schema, AggregationType<T, Aggregations, Column, Alias, 'max', HasSelect>, true, {}, OriginalT>;
|
|
106
|
+
getTableName(): string;
|
|
107
|
+
getFormatter(): SQLFormatter;
|
|
108
|
+
toSQL(): string;
|
|
109
|
+
toSQLWithParams(): {
|
|
110
|
+
sql: string;
|
|
111
|
+
parameters: any[];
|
|
112
|
+
};
|
|
113
|
+
execute(): Promise<T[]>;
|
|
114
|
+
stream(): Promise<ReadableStream<T[]>>;
|
|
115
|
+
/**
|
|
116
|
+
* Processes each row in a stream with the provided callback function
|
|
117
|
+
* @param callback Function to call for each row in the stream
|
|
118
|
+
*/
|
|
119
|
+
streamForEach<R = void>(callback: (row: T) => R | Promise<R>): Promise<void>;
|
|
120
|
+
private validateFilterValue;
|
|
121
|
+
/**
|
|
122
|
+
* Adds a WHERE clause to filter results.
|
|
123
|
+
* @template K - The column key type
|
|
124
|
+
* @param {K} column - The column to filter on
|
|
125
|
+
* @param {FilterOperator} operator - The comparison operator
|
|
126
|
+
* @param {any} value - The value to compare against
|
|
127
|
+
* @returns {this} The current QueryBuilder instance
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* builder.where('age', 'gt', 18)
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
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;
|
|
134
|
+
/**
|
|
135
|
+
* Adds a WHERE clause for tuple IN operations.
|
|
136
|
+
* @template K - The column keys type
|
|
137
|
+
* @param {K[]} columns - The columns to filter on (for tuple operations)
|
|
138
|
+
* @param {'inTuple' | 'globalInTuple'} operator - The tuple IN operator
|
|
139
|
+
* @param {any} value - The array of tuples to compare against
|
|
140
|
+
* @returns {this} The current QueryBuilder instance
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* builder.where(['counter_id', 'user_id'], 'inTuple', [[34, 123], [101500, 456]])
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
where<K extends keyof OriginalT | TableColumn<Schema>>(columns: K[], operator: 'inTuple' | 'globalInTuple', value: any): this;
|
|
147
|
+
orWhere<K extends keyof OriginalT | TableColumn<Schema>>(column: K, operator: FilterOperator, value: any): this;
|
|
148
|
+
/**
|
|
149
|
+
* Adds an OR WHERE clause for tuple IN operations.
|
|
150
|
+
* @template K - The column keys type
|
|
151
|
+
* @param {K[]} columns - The columns to filter on (for tuple operations)
|
|
152
|
+
* @param {'inTuple' | 'globalInTuple'} operator - The tuple IN operator
|
|
153
|
+
* @param {any} value - The array of tuples to compare against
|
|
154
|
+
* @returns {this} The current QueryBuilder instance
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* builder.orWhere(['counter_id', 'user_id'], 'inTuple', [[34, 123], [101500, 456]])
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
orWhere<K extends keyof OriginalT | TableColumn<Schema>>(columns: K[], operator: 'inTuple' | 'globalInTuple', value: any): this;
|
|
161
|
+
/**
|
|
162
|
+
* Creates a parenthesized group of WHERE conditions joined with AND/OR operators.
|
|
163
|
+
* @param {Function} callback - Function that builds the conditions within the group
|
|
164
|
+
* @returns {this} The current QueryBuilder instance
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* builder.whereGroup(qb => {
|
|
168
|
+
* qb.where('status', 'eq', 'active').orWhere('status', 'eq', 'pending');
|
|
169
|
+
* })
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
whereGroup(callback: (builder: this) => void): this;
|
|
173
|
+
/**
|
|
174
|
+
* Creates a parenthesized group of WHERE conditions joined with OR operator.
|
|
175
|
+
* @param {Function} callback - Function that builds the conditions within the group
|
|
176
|
+
* @returns {this} The current QueryBuilder instance
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* builder.orWhereGroup(qb => {
|
|
180
|
+
* qb.where('status', 'eq', 'active').orWhere('status', 'eq', 'pending');
|
|
181
|
+
* })
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
orWhereGroup(callback: (builder: this) => void): this;
|
|
185
|
+
/**
|
|
186
|
+
* Adds a GROUP BY clause.
|
|
187
|
+
* @param {keyof T | Array<keyof T>} columns - Column(s) to group by
|
|
188
|
+
* @returns {this} The current QueryBuilder instance
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* builder.groupBy(['category', 'status'])
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
groupBy(columns: (keyof T | TableColumn<Schema>) | Array<keyof T | TableColumn<Schema>>): this;
|
|
195
|
+
limit(count: number): this;
|
|
196
|
+
offset(count: number): this;
|
|
197
|
+
/**
|
|
198
|
+
* Adds an ORDER BY clause.
|
|
199
|
+
* @param {keyof T} column - The column to order by
|
|
200
|
+
* @param {OrderDirection} [direction='ASC'] - The sort direction
|
|
201
|
+
* @returns {this} The current QueryBuilder instance
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* builder.orderBy('created_at', 'DESC')
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
orderBy<K extends keyof T | TableColumn<Schema>>(column: K, direction?: OrderDirection): this;
|
|
208
|
+
/**
|
|
209
|
+
* Adds a HAVING clause for filtering grouped results.
|
|
210
|
+
* @param {string} condition - The HAVING condition
|
|
211
|
+
* @returns {this} The current QueryBuilder instance
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* builder.having('COUNT(*) > 5')
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
having(condition: string, parameters?: any[]): this;
|
|
218
|
+
distinct(): this;
|
|
219
|
+
whereBetween<K extends keyof OriginalT>(column: K, [min, max]: [
|
|
220
|
+
OriginalT[K] extends ColumnType ? InferColumnType<OriginalT[K]> : never,
|
|
221
|
+
OriginalT[K] extends ColumnType ? InferColumnType<OriginalT[K]> : never
|
|
222
|
+
]): this;
|
|
223
|
+
innerJoin<TableName extends keyof Schema>(table: TableName, leftColumn: keyof OriginalT, rightColumn: `${TableName & string}.${keyof Schema[TableName] & string}`, alias?: string): QueryBuilder<Schema, T, HasSelect, Aggregations, OriginalT>;
|
|
224
|
+
leftJoin<TableName extends keyof Schema>(table: TableName, leftColumn: keyof OriginalT, rightColumn: `${TableName & string}.${keyof Schema[TableName] & string}`, alias?: string): QueryBuilder<Schema, T, HasSelect, Aggregations, OriginalT>;
|
|
225
|
+
rightJoin<TableName extends keyof Schema>(table: TableName, leftColumn: keyof OriginalT, rightColumn: `${TableName & string}.${keyof Schema[TableName] & string}`, alias?: string): QueryBuilder<Schema, T, HasSelect, Aggregations, OriginalT>;
|
|
226
|
+
fullJoin<TableName extends keyof Schema>(table: TableName, leftColumn: keyof OriginalT, rightColumn: `${TableName & string}.${keyof Schema[TableName] & string}`, alias?: string): QueryBuilder<Schema, T, HasSelect, Aggregations, OriginalT>;
|
|
227
|
+
getConfig(): QueryConfig<T, Schema>;
|
|
228
|
+
/**
|
|
229
|
+
* Paginates the query results using cursor-based pagination
|
|
230
|
+
*/
|
|
231
|
+
paginate(options: PaginationOptions<T>): Promise<PaginatedResult<T>>;
|
|
232
|
+
/**
|
|
233
|
+
* Gets the first page of results
|
|
234
|
+
*/
|
|
235
|
+
firstPage(pageSize: number): Promise<PaginatedResult<T>>;
|
|
236
|
+
/**
|
|
237
|
+
* Returns an async iterator that yields all pages
|
|
238
|
+
*/
|
|
239
|
+
iteratePages(pageSize: number): AsyncGenerator<PaginatedResult<T>>;
|
|
240
|
+
static setJoinRelationships<S extends {
|
|
241
|
+
[K in keyof S]: {
|
|
242
|
+
[columnName: string]: ColumnType;
|
|
243
|
+
};
|
|
244
|
+
}>(relationships: JoinRelationships<S>): void;
|
|
245
|
+
/**
|
|
246
|
+
* Apply a predefined join relationship
|
|
247
|
+
*/
|
|
248
|
+
withRelation(name: string, options?: JoinPathOptions): this;
|
|
249
|
+
}
|
|
250
|
+
export declare function createQueryBuilder<Schema extends {
|
|
251
|
+
[K in keyof Schema]: {
|
|
252
|
+
[columnName: string]: ColumnType;
|
|
253
|
+
};
|
|
254
|
+
}>(config: ClickHouseConfig): {
|
|
255
|
+
table<TableName extends keyof Schema>(tableName: TableName): QueryBuilder<Schema, Schema[TableName], false, {}>;
|
|
256
|
+
};
|
|
257
|
+
export {};
|
|
258
|
+
//# 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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E,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,13 +1,20 @@
|
|
|
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';
|
|
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
|
+
/**
|
|
13
|
+
* Type guard to check if a config is a client-based configuration.
|
|
14
|
+
*/
|
|
15
|
+
export function isClientConfig(config) {
|
|
16
|
+
return 'client' in config && !('host' in config);
|
|
17
|
+
}
|
|
11
18
|
/**
|
|
12
19
|
* A type-safe query builder for ClickHouse databases.
|
|
13
20
|
* @template Schema - The full database schema
|
|
@@ -29,6 +36,7 @@ export class QueryBuilder {
|
|
|
29
36
|
this.executor = new ExecutorFeature(this);
|
|
30
37
|
this.modifiers = new QueryModifiersFeature(this);
|
|
31
38
|
this.pagination = new PaginationFeature(this);
|
|
39
|
+
this.crossFiltering = new CrossFilteringFeature(this);
|
|
32
40
|
}
|
|
33
41
|
debug() {
|
|
34
42
|
console.log('Current Type:', {
|
|
@@ -49,6 +57,7 @@ export class QueryBuilder {
|
|
|
49
57
|
newBuilder.executor = new ExecutorFeature(newBuilder);
|
|
50
58
|
newBuilder.modifiers = new QueryModifiersFeature(newBuilder);
|
|
51
59
|
newBuilder.pagination = new PaginationFeature(newBuilder);
|
|
60
|
+
newBuilder.crossFiltering = new CrossFilteringFeature(newBuilder);
|
|
52
61
|
return newBuilder;
|
|
53
62
|
}
|
|
54
63
|
// --- Analytics Helper: Add a CTE.
|
|
@@ -92,12 +101,7 @@ export class QueryBuilder {
|
|
|
92
101
|
* @returns The current QueryBuilder instance.
|
|
93
102
|
*/
|
|
94
103
|
applyCrossFilters(crossFilter) {
|
|
95
|
-
|
|
96
|
-
filterGroup.conditions.forEach((item) => {
|
|
97
|
-
if ('column' in item) {
|
|
98
|
-
this.where(item.column, item.operator, item.value);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
104
|
+
this.config = this.crossFiltering.applyCrossFilters(crossFilter);
|
|
101
105
|
return this;
|
|
102
106
|
}
|
|
103
107
|
/**
|
|
@@ -200,30 +204,87 @@ export class QueryBuilder {
|
|
|
200
204
|
}
|
|
201
205
|
}
|
|
202
206
|
validateFilterValue(column, operator, value) {
|
|
207
|
+
// Handle tuple columns
|
|
208
|
+
if (Array.isArray(column)) {
|
|
209
|
+
// For tuple operations, we don't validate individual column types
|
|
210
|
+
// as they might be cross-table references
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
// Skip validation for advanced IN operators - they handle their own validation
|
|
214
|
+
const advancedInOperators = [
|
|
215
|
+
'globalIn', 'globalNotIn', 'inSubquery', 'globalInSubquery',
|
|
216
|
+
'inTable', 'globalInTable', 'inTuple', 'globalInTuple'
|
|
217
|
+
];
|
|
218
|
+
if (advancedInOperators.includes(operator)) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
203
221
|
if (FilterValidator.validateJoinedColumn(String(column)))
|
|
204
222
|
return;
|
|
205
223
|
const columnType = this.schema.columns[column];
|
|
206
224
|
FilterValidator.validateFilterCondition({ column: String(column), operator, value }, columnType);
|
|
207
225
|
}
|
|
226
|
+
where(columnOrColumns, operator, value) {
|
|
227
|
+
// Handle tuple operations
|
|
228
|
+
if (Array.isArray(columnOrColumns) && (operator === 'inTuple' || operator === 'globalInTuple')) {
|
|
229
|
+
// For tuple operations, we need to handle the column array specially
|
|
230
|
+
const columns = columnOrColumns;
|
|
231
|
+
this.validateFilterValue(columns, operator, value);
|
|
232
|
+
this.config = this.filtering.addCondition('AND', columns, operator, value);
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
// Handle regular operations
|
|
236
|
+
const column = columnOrColumns;
|
|
237
|
+
this.validateFilterValue(column, operator, value);
|
|
238
|
+
this.config = this.filtering.addCondition('AND', column, operator, value);
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
orWhere(columnOrColumns, operator, value) {
|
|
242
|
+
// Handle tuple operations
|
|
243
|
+
if (Array.isArray(columnOrColumns) && (operator === 'inTuple' || operator === 'globalInTuple')) {
|
|
244
|
+
// For tuple operations, we need to handle the column array specially
|
|
245
|
+
const columns = columnOrColumns;
|
|
246
|
+
this.validateFilterValue(columns, operator, value);
|
|
247
|
+
this.config = this.filtering.addCondition('OR', columns, operator, value);
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
// Handle regular operations
|
|
251
|
+
const column = columnOrColumns;
|
|
252
|
+
this.validateFilterValue(column, operator, value);
|
|
253
|
+
this.config = this.filtering.addCondition('OR', column, operator, value);
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
208
256
|
/**
|
|
209
|
-
*
|
|
210
|
-
* @
|
|
211
|
-
* @param {K} column - The column to filter on
|
|
212
|
-
* @param {FilterOperator} operator - The comparison operator
|
|
213
|
-
* @param {any} value - The value to compare against
|
|
257
|
+
* Creates a parenthesized group of WHERE conditions joined with AND/OR operators.
|
|
258
|
+
* @param {Function} callback - Function that builds the conditions within the group
|
|
214
259
|
* @returns {this} The current QueryBuilder instance
|
|
215
260
|
* @example
|
|
216
261
|
* ```ts
|
|
217
|
-
* builder.
|
|
262
|
+
* builder.whereGroup(qb => {
|
|
263
|
+
* qb.where('status', 'eq', 'active').orWhere('status', 'eq', 'pending');
|
|
264
|
+
* })
|
|
218
265
|
* ```
|
|
219
266
|
*/
|
|
220
|
-
|
|
221
|
-
this.
|
|
222
|
-
this
|
|
267
|
+
whereGroup(callback) {
|
|
268
|
+
this.config = this.filtering.startWhereGroup();
|
|
269
|
+
callback(this);
|
|
270
|
+
this.config = this.filtering.endWhereGroup();
|
|
223
271
|
return this;
|
|
224
272
|
}
|
|
225
|
-
|
|
226
|
-
|
|
273
|
+
/**
|
|
274
|
+
* Creates a parenthesized group of WHERE conditions joined with OR operator.
|
|
275
|
+
* @param {Function} callback - Function that builds the conditions within the group
|
|
276
|
+
* @returns {this} The current QueryBuilder instance
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts
|
|
279
|
+
* builder.orWhereGroup(qb => {
|
|
280
|
+
* qb.where('status', 'eq', 'active').orWhere('status', 'eq', 'pending');
|
|
281
|
+
* })
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
orWhereGroup(callback) {
|
|
285
|
+
this.config = this.filtering.startOrWhereGroup();
|
|
286
|
+
callback(this);
|
|
287
|
+
this.config = this.filtering.endWhereGroup();
|
|
227
288
|
return this;
|
|
228
289
|
}
|
|
229
290
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination-test-tbc.d.ts","sourceRoot":"","sources":["../../../../src/core/tests/integration/pagination-test-tbc.ts"],"names":[],"mappings":""}
|