@hypequery/clickhouse 0.2.1 → 0.2.3
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/bin.js +128 -36
- package/dist/cli/generate-types.js +101 -12
- package/dist/core/connection.d.ts +136 -0
- package/dist/core/connection.d.ts.map +1 -1
- package/dist/core/connection.js +58 -0
- package/dist/core/cross-filter.d.ts +85 -0
- package/dist/core/features/aggregations.d.ts +102 -0
- package/dist/core/features/analytics.d.ts +66 -0
- 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/filtering.d.ts +95 -0
- package/dist/core/features/filtering.d.ts.map +1 -1
- package/dist/core/features/filtering.js +59 -1
- 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 +24 -5
- package/dist/core/join-relationships.d.ts +50 -0
- package/dist/core/query-builder.d.ts +222 -0
- package/dist/core/query-builder.d.ts.map +1 -1
- package/dist/core/query-builder.js +38 -6
- 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 +278 -237
- 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/test-utils.d.ts +30 -0
- package/dist/core/utils/logger.d.ts +37 -0
- package/dist/core/utils/logger.js +2 -2
- package/dist/core/utils/sql-expressions.d.ts +59 -0
- package/dist/core/utils.d.ts +3 -0
- package/dist/core/validators/filter-validator.d.ts +8 -0
- package/dist/core/validators/value-validator.d.ts +6 -0
- package/dist/formatters/index.d.ts +1 -0
- package/dist/index.d.ts +10 -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/filters.d.ts +37 -0
- package/dist/types/index.d.ts +3 -0
- package/package.json +15 -8
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { QueryBuilder } from '../query-builder';
|
|
2
|
+
import { ColumnType, OrderDirection, TableColumn } from '../../types';
|
|
3
|
+
export declare class QueryModifiersFeature<Schema extends {
|
|
4
|
+
[tableName: string]: {
|
|
5
|
+
[columnName: string]: ColumnType;
|
|
6
|
+
};
|
|
7
|
+
}, T, HasSelect extends boolean = false, Aggregations = {}, OriginalT = T> {
|
|
8
|
+
private builder;
|
|
9
|
+
constructor(builder: QueryBuilder<Schema, T, HasSelect, Aggregations, OriginalT>);
|
|
10
|
+
addGroupBy(columns: (keyof T | TableColumn<Schema>) | Array<keyof T | TableColumn<Schema>>): {
|
|
11
|
+
groupBy: string[];
|
|
12
|
+
select?: (string | keyof T)[] | undefined;
|
|
13
|
+
where?: import("../../types").WhereCondition[];
|
|
14
|
+
having?: string[];
|
|
15
|
+
limit?: number;
|
|
16
|
+
offset?: number;
|
|
17
|
+
distinct?: boolean;
|
|
18
|
+
orderBy?: {
|
|
19
|
+
column: TableColumn<Schema> | keyof T;
|
|
20
|
+
direction: OrderDirection;
|
|
21
|
+
}[] | undefined;
|
|
22
|
+
joins?: import("../../types").JoinClause[];
|
|
23
|
+
parameters?: any[];
|
|
24
|
+
ctes?: string[];
|
|
25
|
+
unionQueries?: string[];
|
|
26
|
+
settings?: string;
|
|
27
|
+
};
|
|
28
|
+
addLimit(count: number): {
|
|
29
|
+
limit: number;
|
|
30
|
+
select?: (string | keyof T)[] | undefined;
|
|
31
|
+
where?: import("../../types").WhereCondition[];
|
|
32
|
+
groupBy?: string[];
|
|
33
|
+
having?: string[];
|
|
34
|
+
offset?: number;
|
|
35
|
+
distinct?: boolean;
|
|
36
|
+
orderBy?: {
|
|
37
|
+
column: TableColumn<Schema> | keyof T;
|
|
38
|
+
direction: OrderDirection;
|
|
39
|
+
}[] | undefined;
|
|
40
|
+
joins?: import("../../types").JoinClause[];
|
|
41
|
+
parameters?: any[];
|
|
42
|
+
ctes?: string[];
|
|
43
|
+
unionQueries?: string[];
|
|
44
|
+
settings?: string;
|
|
45
|
+
};
|
|
46
|
+
addOffset(count: number): {
|
|
47
|
+
offset: number;
|
|
48
|
+
select?: (string | keyof T)[] | undefined;
|
|
49
|
+
where?: import("../../types").WhereCondition[];
|
|
50
|
+
groupBy?: string[];
|
|
51
|
+
having?: string[];
|
|
52
|
+
limit?: number;
|
|
53
|
+
distinct?: boolean;
|
|
54
|
+
orderBy?: {
|
|
55
|
+
column: TableColumn<Schema> | keyof T;
|
|
56
|
+
direction: OrderDirection;
|
|
57
|
+
}[] | undefined;
|
|
58
|
+
joins?: import("../../types").JoinClause[];
|
|
59
|
+
parameters?: any[];
|
|
60
|
+
ctes?: string[];
|
|
61
|
+
unionQueries?: string[];
|
|
62
|
+
settings?: string;
|
|
63
|
+
};
|
|
64
|
+
addOrderBy<K extends keyof T | TableColumn<Schema>>(column: K, direction?: OrderDirection): {
|
|
65
|
+
orderBy: {
|
|
66
|
+
column: TableColumn<Schema> | keyof T;
|
|
67
|
+
direction: OrderDirection;
|
|
68
|
+
}[];
|
|
69
|
+
select?: (string | keyof T)[] | undefined;
|
|
70
|
+
where?: import("../../types").WhereCondition[];
|
|
71
|
+
groupBy?: string[];
|
|
72
|
+
having?: string[];
|
|
73
|
+
limit?: number;
|
|
74
|
+
offset?: number;
|
|
75
|
+
distinct?: boolean;
|
|
76
|
+
joins?: import("../../types").JoinClause[];
|
|
77
|
+
parameters?: any[];
|
|
78
|
+
ctes?: string[];
|
|
79
|
+
unionQueries?: string[];
|
|
80
|
+
settings?: string;
|
|
81
|
+
};
|
|
82
|
+
addHaving(condition: string, parameters?: any[]): {
|
|
83
|
+
having: string[];
|
|
84
|
+
parameters: any[] | undefined;
|
|
85
|
+
select?: (string | keyof T)[] | undefined;
|
|
86
|
+
where?: import("../../types").WhereCondition[];
|
|
87
|
+
groupBy?: string[];
|
|
88
|
+
limit?: number;
|
|
89
|
+
offset?: number;
|
|
90
|
+
distinct?: boolean;
|
|
91
|
+
orderBy?: {
|
|
92
|
+
column: TableColumn<Schema> | keyof T;
|
|
93
|
+
direction: OrderDirection;
|
|
94
|
+
}[] | undefined;
|
|
95
|
+
joins?: import("../../types").JoinClause[];
|
|
96
|
+
ctes?: string[];
|
|
97
|
+
unionQueries?: string[];
|
|
98
|
+
settings?: string;
|
|
99
|
+
};
|
|
100
|
+
setDistinct(): {
|
|
101
|
+
distinct: boolean;
|
|
102
|
+
select?: (string | keyof T)[] | undefined;
|
|
103
|
+
where?: import("../../types").WhereCondition[];
|
|
104
|
+
groupBy?: string[];
|
|
105
|
+
having?: string[];
|
|
106
|
+
limit?: number;
|
|
107
|
+
offset?: number;
|
|
108
|
+
orderBy?: {
|
|
109
|
+
column: TableColumn<Schema> | keyof T;
|
|
110
|
+
direction: OrderDirection;
|
|
111
|
+
}[] | undefined;
|
|
112
|
+
joins?: import("../../types").JoinClause[];
|
|
113
|
+
parameters?: any[];
|
|
114
|
+
ctes?: string[];
|
|
115
|
+
unionQueries?: string[];
|
|
116
|
+
settings?: string;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=query-modifiers.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { QueryConfig } from '../../types';
|
|
2
|
+
export declare class SQLFormatter {
|
|
3
|
+
formatSelect(config: QueryConfig<any, any>): string;
|
|
4
|
+
formatGroupBy(config: QueryConfig<any, any>): string;
|
|
5
|
+
formatWhere(config: QueryConfig<any, any>): string;
|
|
6
|
+
private getSqlOperator;
|
|
7
|
+
formatJoins(config: QueryConfig<any, any>): string;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=sql-formatter.d.ts.map
|
|
@@ -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;IAuDlD,OAAO,CAAC,cAAc;IActB,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,MAAM;CAUnD"}
|
|
@@ -17,10 +17,25 @@ export class SQLFormatter {
|
|
|
17
17
|
formatWhere(config) {
|
|
18
18
|
if (!config.where?.length)
|
|
19
19
|
return '';
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
let afterGroupStart = false; // Track whether we're immediately after a group-start
|
|
21
|
+
// First pass - generate the SQL fragments for each condition
|
|
22
|
+
const fragments = config.where.map((condition, index) => {
|
|
23
|
+
// Handle special group markers
|
|
24
|
+
if (condition.type === 'group-start') {
|
|
25
|
+
const prefix = index === 0 ? '' : ` ${condition.conjunction} `;
|
|
26
|
+
afterGroupStart = true; // Mark that the next condition follows a group-start
|
|
27
|
+
return `${prefix}(`.trim();
|
|
28
|
+
}
|
|
29
|
+
if (condition.type === 'group-end') {
|
|
30
|
+
afterGroupStart = false; // Reset the flag after group-end
|
|
31
|
+
return ')';
|
|
32
|
+
}
|
|
33
|
+
// Normal conditions
|
|
22
34
|
const { column, operator, value, conjunction } = condition;
|
|
23
|
-
|
|
35
|
+
// Don't add conjunction if it's the first condition or right after a group-start
|
|
36
|
+
const prefix = index === 0 || afterGroupStart ? '' : ` ${conjunction} `;
|
|
37
|
+
// Reset the afterGroupStart flag
|
|
38
|
+
afterGroupStart = false;
|
|
24
39
|
if (operator === 'in' || operator === 'notIn') {
|
|
25
40
|
if (!Array.isArray(value)) {
|
|
26
41
|
throw new Error(`Expected an array for ${operator} operator, but got ${typeof value}`);
|
|
@@ -40,8 +55,12 @@ export class SQLFormatter {
|
|
|
40
55
|
else {
|
|
41
56
|
return `${prefix}${column} ${this.getSqlOperator(operator)} ?`.trim();
|
|
42
57
|
}
|
|
43
|
-
})
|
|
44
|
-
|
|
58
|
+
});
|
|
59
|
+
// Join fragments and then remove extra spaces around parentheses
|
|
60
|
+
let result = fragments.join(' ');
|
|
61
|
+
// Replace "( " with "(" and " )" with ")"
|
|
62
|
+
result = result.replace(/\(\s+/g, '(').replace(/\s+\)/g, ')');
|
|
63
|
+
return result;
|
|
45
64
|
}
|
|
46
65
|
getSqlOperator(operator) {
|
|
47
66
|
switch (operator) {
|
|
@@ -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
|
+
[tableName: string]: {
|
|
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
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { CrossFilter } from './cross-filter';
|
|
2
|
+
import { ColumnType, FilterOperator, OrderDirection, TableColumn, AggregationType, QueryConfig, OperatorValueMap, InferColumnType, PaginationOptions, PaginatedResult } from '../types';
|
|
3
|
+
import { ClickHouseSettings } from '@clickhouse/client-web';
|
|
4
|
+
import { SQLFormatter } from './formatters/sql-formatter';
|
|
5
|
+
import { JoinRelationships, JoinPathOptions } from './join-relationships';
|
|
6
|
+
import { SqlExpression } from './utils/sql-expressions';
|
|
7
|
+
/**
|
|
8
|
+
* A type-safe query builder for ClickHouse databases.
|
|
9
|
+
* @template Schema - The full database schema
|
|
10
|
+
* @template T - The schema type of the current table
|
|
11
|
+
* @template HasSelect - Whether a SELECT clause has been applied
|
|
12
|
+
* @template Aggregations - The type of any aggregation functions applied
|
|
13
|
+
*/
|
|
14
|
+
export declare class QueryBuilder<Schema extends {
|
|
15
|
+
[tableName: string]: {
|
|
16
|
+
[columnName: string]: ColumnType;
|
|
17
|
+
};
|
|
18
|
+
}, T, HasSelect extends boolean = false, Aggregations = {}, OriginalT = T> {
|
|
19
|
+
private static relationships;
|
|
20
|
+
private config;
|
|
21
|
+
private tableName;
|
|
22
|
+
private schema;
|
|
23
|
+
private originalSchema;
|
|
24
|
+
private formatter;
|
|
25
|
+
private aggregations;
|
|
26
|
+
private joins;
|
|
27
|
+
private filtering;
|
|
28
|
+
private analytics;
|
|
29
|
+
private executor;
|
|
30
|
+
private modifiers;
|
|
31
|
+
private pagination;
|
|
32
|
+
private crossFiltering;
|
|
33
|
+
constructor(tableName: string, schema: {
|
|
34
|
+
name: string;
|
|
35
|
+
columns: T;
|
|
36
|
+
}, originalSchema: Schema);
|
|
37
|
+
debug(): this;
|
|
38
|
+
clone(): QueryBuilder<Schema, T, HasSelect, Aggregations, OriginalT>;
|
|
39
|
+
withCTE(alias: string, subquery: QueryBuilder<any, any> | string): this;
|
|
40
|
+
/**
|
|
41
|
+
* Groups results by a time interval using a specified ClickHouse function.
|
|
42
|
+
*
|
|
43
|
+
* @param column - The column containing the date or timestamp.
|
|
44
|
+
* @param interval - The interval value. For example, "1 day" or "15 minute".
|
|
45
|
+
* This is only used when the method is 'toStartOfInterval'.
|
|
46
|
+
* @param method - The time bucketing function to use.
|
|
47
|
+
* Defaults to 'toStartOfInterval'.
|
|
48
|
+
* Other valid values include 'toStartOfMinute', 'toStartOfHour',
|
|
49
|
+
* 'toStartOfDay', 'toStartOfWeek', 'toStartOfMonth', 'toStartOfQuarter', and 'toStartOfYear'.
|
|
50
|
+
* @returns The current QueryBuilder instance.
|
|
51
|
+
*/
|
|
52
|
+
groupByTimeInterval(column: keyof T | TableColumn<Schema>, interval: string, method?: 'toStartOfInterval' | 'toStartOfMinute' | 'toStartOfHour' | 'toStartOfDay' | 'toStartOfWeek' | 'toStartOfMonth' | 'toStartOfQuarter' | 'toStartOfYear'): this;
|
|
53
|
+
raw(sql: string): this;
|
|
54
|
+
settings(opts: ClickHouseSettings): this;
|
|
55
|
+
/**
|
|
56
|
+
* Applies a set of cross filters to the current query.
|
|
57
|
+
* All filter conditions from the provided CrossFilter are added to the query.
|
|
58
|
+
* @param crossFilter - An instance of CrossFilter containing shared filter conditions.
|
|
59
|
+
* @returns The current QueryBuilder instance.
|
|
60
|
+
*/
|
|
61
|
+
applyCrossFilters(crossFilter: CrossFilter<Schema, keyof Schema>): this;
|
|
62
|
+
/**
|
|
63
|
+
* Selects specific columns from the table.
|
|
64
|
+
* @template K - The keys/columns to select
|
|
65
|
+
* @param {K[]} columns - Array of column names to select
|
|
66
|
+
* @returns {QueryBuilder} A new QueryBuilder instance with updated types
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* builder.select(['id', 'name'])
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
select<K extends keyof T | TableColumn<Schema> | SqlExpression>(columns: K[]): QueryBuilder<Schema, {
|
|
73
|
+
[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;
|
|
74
|
+
}, true, Aggregations, OriginalT>;
|
|
75
|
+
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>;
|
|
76
|
+
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>;
|
|
77
|
+
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>;
|
|
78
|
+
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>;
|
|
79
|
+
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>;
|
|
80
|
+
getTableName(): string;
|
|
81
|
+
getFormatter(): SQLFormatter;
|
|
82
|
+
toSQL(): string;
|
|
83
|
+
toSQLWithParams(): {
|
|
84
|
+
sql: string;
|
|
85
|
+
parameters: any[];
|
|
86
|
+
};
|
|
87
|
+
execute(): Promise<T[]>;
|
|
88
|
+
stream(): Promise<ReadableStream<T[]>>;
|
|
89
|
+
/**
|
|
90
|
+
* Processes each row in a stream with the provided callback function
|
|
91
|
+
* @param callback Function to call for each row in the stream
|
|
92
|
+
*/
|
|
93
|
+
streamForEach<R = void>(callback: (row: T) => R | Promise<R>): Promise<void>;
|
|
94
|
+
private validateFilterValue;
|
|
95
|
+
/**
|
|
96
|
+
* Adds a WHERE clause to filter results.
|
|
97
|
+
* @template K - The column key type
|
|
98
|
+
* @param {K} column - The column to filter on
|
|
99
|
+
* @param {FilterOperator} operator - The comparison operator
|
|
100
|
+
* @param {any} value - The value to compare against
|
|
101
|
+
* @returns {this} The current QueryBuilder instance
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* builder.where('age', 'gt', 18)
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
where<K extends keyof OriginalT | TableColumn<Schema>, Op extends keyof OperatorValueMap<any>>(column: K, operator: Op, value: K extends keyof OriginalT ? OperatorValueMap<OriginalT[K] extends ColumnType ? InferColumnType<OriginalT[K]> : never>[Op] : any): this;
|
|
108
|
+
orWhere<K extends keyof OriginalT | TableColumn<Schema>>(column: K, operator: FilterOperator, value: any): this;
|
|
109
|
+
/**
|
|
110
|
+
* Creates a parenthesized group of WHERE conditions joined with AND/OR operators.
|
|
111
|
+
* @param {Function} callback - Function that builds the conditions within the group
|
|
112
|
+
* @returns {this} The current QueryBuilder instance
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* builder.whereGroup(qb => {
|
|
116
|
+
* qb.where('status', 'eq', 'active').orWhere('status', 'eq', 'pending');
|
|
117
|
+
* })
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
whereGroup(callback: (builder: this) => void): this;
|
|
121
|
+
/**
|
|
122
|
+
* Creates a parenthesized group of WHERE conditions joined with OR operator.
|
|
123
|
+
* @param {Function} callback - Function that builds the conditions within the group
|
|
124
|
+
* @returns {this} The current QueryBuilder instance
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* builder.orWhereGroup(qb => {
|
|
128
|
+
* qb.where('status', 'eq', 'active').orWhere('status', 'eq', 'pending');
|
|
129
|
+
* })
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
orWhereGroup(callback: (builder: this) => void): this;
|
|
133
|
+
/**
|
|
134
|
+
* Adds a GROUP BY clause.
|
|
135
|
+
* @param {keyof T | Array<keyof T>} columns - Column(s) to group by
|
|
136
|
+
* @returns {this} The current QueryBuilder instance
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* builder.groupBy(['category', 'status'])
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
groupBy(columns: (keyof T | TableColumn<Schema>) | Array<keyof T | TableColumn<Schema>>): this;
|
|
143
|
+
limit(count: number): this;
|
|
144
|
+
offset(count: number): this;
|
|
145
|
+
/**
|
|
146
|
+
* Adds an ORDER BY clause.
|
|
147
|
+
* @param {keyof T} column - The column to order by
|
|
148
|
+
* @param {OrderDirection} [direction='ASC'] - The sort direction
|
|
149
|
+
* @returns {this} The current QueryBuilder instance
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* builder.orderBy('created_at', 'DESC')
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
orderBy<K extends keyof T | TableColumn<Schema>>(column: K, direction?: OrderDirection): this;
|
|
156
|
+
/**
|
|
157
|
+
* Adds a HAVING clause for filtering grouped results.
|
|
158
|
+
* @param {string} condition - The HAVING condition
|
|
159
|
+
* @returns {this} The current QueryBuilder instance
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* builder.having('COUNT(*) > 5')
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
having(condition: string, parameters?: any[]): this;
|
|
166
|
+
distinct(): this;
|
|
167
|
+
whereBetween<K extends keyof OriginalT>(column: K, [min, max]: [
|
|
168
|
+
OriginalT[K] extends ColumnType ? InferColumnType<OriginalT[K]> : never,
|
|
169
|
+
OriginalT[K] extends ColumnType ? InferColumnType<OriginalT[K]> : never
|
|
170
|
+
]): this;
|
|
171
|
+
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>;
|
|
172
|
+
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>;
|
|
173
|
+
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>;
|
|
174
|
+
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>;
|
|
175
|
+
getConfig(): QueryConfig<T, Schema>;
|
|
176
|
+
/**
|
|
177
|
+
* Paginates the query results using cursor-based pagination
|
|
178
|
+
*/
|
|
179
|
+
paginate(options: PaginationOptions<T>): Promise<PaginatedResult<T>>;
|
|
180
|
+
/**
|
|
181
|
+
* Gets the first page of results
|
|
182
|
+
*/
|
|
183
|
+
firstPage(pageSize: number): Promise<PaginatedResult<T>>;
|
|
184
|
+
/**
|
|
185
|
+
* Returns an async iterator that yields all pages
|
|
186
|
+
*/
|
|
187
|
+
iteratePages(pageSize: number): AsyncGenerator<PaginatedResult<T>>;
|
|
188
|
+
static setJoinRelationships<S extends {
|
|
189
|
+
[tableName: string]: {
|
|
190
|
+
[columnName: string]: ColumnType;
|
|
191
|
+
};
|
|
192
|
+
}>(relationships: JoinRelationships<S>): void;
|
|
193
|
+
/**
|
|
194
|
+
* Apply a predefined join relationship
|
|
195
|
+
*/
|
|
196
|
+
withRelation(name: string, options?: JoinPathOptions): this;
|
|
197
|
+
}
|
|
198
|
+
export declare function createQueryBuilder<Schema extends {
|
|
199
|
+
[K in keyof Schema]: {
|
|
200
|
+
[columnName: string]: ColumnType;
|
|
201
|
+
};
|
|
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
|
+
}): {
|
|
220
|
+
table<TableName extends keyof Schema>(tableName: TableName): QueryBuilder<Schema, Schema[TableName], false, {}>;
|
|
221
|
+
};
|
|
222
|
+
//# 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,
|
|
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,wBAAwB,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAS1D,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAO,MAAM,yBAAyB,CAAC;AAG7D;;;;;;GAMG;AACH,qBAAa,YAAY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,UAAU,EAAE,MAAM,GAAG,UAAU,CAAA;SAAE,CAAA;KAAE,EACjG,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;IACN,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE;QACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;IACF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE;QACX,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,mBAAmB,CAAC,EAAE,kBAAkB,CAAC;CAC1C;UAKO,SAAS,SAAS,MAAM,MAAM,aAAa,SAAS,GAAG,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;EAWlH"}
|
|
@@ -8,6 +8,7 @@ import { ExecutorFeature } from './features/executor';
|
|
|
8
8
|
import { QueryModifiersFeature } from './features/query-modifiers';
|
|
9
9
|
import { FilterValidator } from './validators/filter-validator';
|
|
10
10
|
import { PaginationFeature } from './features/pagination';
|
|
11
|
+
import { CrossFilteringFeature } from './features/cross-filtering';
|
|
11
12
|
/**
|
|
12
13
|
* A type-safe query builder for ClickHouse databases.
|
|
13
14
|
* @template Schema - The full database schema
|
|
@@ -29,6 +30,7 @@ export class QueryBuilder {
|
|
|
29
30
|
this.executor = new ExecutorFeature(this);
|
|
30
31
|
this.modifiers = new QueryModifiersFeature(this);
|
|
31
32
|
this.pagination = new PaginationFeature(this);
|
|
33
|
+
this.crossFiltering = new CrossFilteringFeature(this);
|
|
32
34
|
}
|
|
33
35
|
debug() {
|
|
34
36
|
console.log('Current Type:', {
|
|
@@ -49,6 +51,7 @@ export class QueryBuilder {
|
|
|
49
51
|
newBuilder.executor = new ExecutorFeature(newBuilder);
|
|
50
52
|
newBuilder.modifiers = new QueryModifiersFeature(newBuilder);
|
|
51
53
|
newBuilder.pagination = new PaginationFeature(newBuilder);
|
|
54
|
+
newBuilder.crossFiltering = new CrossFilteringFeature(newBuilder);
|
|
52
55
|
return newBuilder;
|
|
53
56
|
}
|
|
54
57
|
// --- Analytics Helper: Add a CTE.
|
|
@@ -92,12 +95,7 @@ export class QueryBuilder {
|
|
|
92
95
|
* @returns The current QueryBuilder instance.
|
|
93
96
|
*/
|
|
94
97
|
applyCrossFilters(crossFilter) {
|
|
95
|
-
|
|
96
|
-
filterGroup.conditions.forEach((item) => {
|
|
97
|
-
if ('column' in item) {
|
|
98
|
-
this.where(item.column, item.operator, item.value);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
98
|
+
this.config = this.crossFiltering.applyCrossFilters(crossFilter);
|
|
101
99
|
return this;
|
|
102
100
|
}
|
|
103
101
|
/**
|
|
@@ -226,6 +224,40 @@ export class QueryBuilder {
|
|
|
226
224
|
this.config = this.filtering.addCondition('OR', column, operator, value);
|
|
227
225
|
return this;
|
|
228
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Creates a parenthesized group of WHERE conditions joined with AND/OR operators.
|
|
229
|
+
* @param {Function} callback - Function that builds the conditions within the group
|
|
230
|
+
* @returns {this} The current QueryBuilder instance
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* builder.whereGroup(qb => {
|
|
234
|
+
* qb.where('status', 'eq', 'active').orWhere('status', 'eq', 'pending');
|
|
235
|
+
* })
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
whereGroup(callback) {
|
|
239
|
+
this.config = this.filtering.startWhereGroup();
|
|
240
|
+
callback(this);
|
|
241
|
+
this.config = this.filtering.endWhereGroup();
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Creates a parenthesized group of WHERE conditions joined with OR operator.
|
|
246
|
+
* @param {Function} callback - Function that builds the conditions within the group
|
|
247
|
+
* @returns {this} The current QueryBuilder instance
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* builder.orWhereGroup(qb => {
|
|
251
|
+
* qb.where('status', 'eq', 'active').orWhere('status', 'eq', 'pending');
|
|
252
|
+
* })
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
orWhereGroup(callback) {
|
|
256
|
+
this.config = this.filtering.startOrWhereGroup();
|
|
257
|
+
callback(this);
|
|
258
|
+
this.config = this.filtering.endWhereGroup();
|
|
259
|
+
return this;
|
|
260
|
+
}
|
|
229
261
|
/**
|
|
230
262
|
* Adds a GROUP BY clause.
|
|
231
263
|
* @param {keyof T | Array<keyof T>} columns - Column(s) to group by
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination-test-tbc.d.ts","sourceRoot":"","sources":["../../../../src/core/tests/integration/pagination-test-tbc.ts"],"names":[],"mappings":""}
|