@hypequery/clickhouse 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/core/features/aggregations.d.ts +13 -17
- package/dist/core/features/aggregations.d.ts.map +1 -1
- package/dist/core/features/aggregations.js +6 -6
- package/dist/core/features/analytics.d.ts +12 -16
- package/dist/core/features/analytics.d.ts.map +1 -1
- package/dist/core/features/analytics.js +2 -2
- package/dist/core/features/cross-filtering.d.ts +4 -19
- package/dist/core/features/cross-filtering.d.ts.map +1 -1
- package/dist/core/features/cross-filtering.js +0 -33
- package/dist/core/features/executor.d.ts +5 -9
- package/dist/core/features/executor.d.ts.map +1 -1
- package/dist/core/features/filtering.d.ts +14 -30
- package/dist/core/features/filtering.d.ts.map +1 -1
- package/dist/core/features/filtering.js +10 -26
- package/dist/core/features/joins.d.ts +6 -10
- package/dist/core/features/joins.d.ts.map +1 -1
- package/dist/core/features/pagination.d.ts +7 -10
- package/dist/core/features/pagination.d.ts.map +1 -1
- package/dist/core/features/pagination.js +13 -41
- package/dist/core/features/query-modifiers.d.ts +17 -21
- package/dist/core/features/query-modifiers.d.ts.map +1 -1
- package/dist/core/query-builder.d.ts +46 -75
- package/dist/core/query-builder.d.ts.map +1 -1
- package/dist/core/query-builder.js +74 -95
- package/dist/core/tests/integration/setup.d.ts +1 -1
- package/dist/core/tests/test-utils.d.ts +4 -3
- package/dist/core/tests/test-utils.d.ts.map +1 -1
- package/dist/core/tests/test-utils.js +18 -8
- package/dist/core/types/builder-state.d.ts +25 -0
- package/dist/core/types/builder-state.d.ts.map +1 -0
- package/dist/core/types/builder-state.js +1 -0
- package/dist/core/types/select-types.d.ts +25 -0
- package/dist/core/types/select-types.d.ts.map +1 -0
- package/dist/core/types/select-types.js +1 -0
- package/dist/core/types/type-helpers.d.ts +5 -0
- package/dist/core/types/type-helpers.d.ts.map +1 -0
- package/dist/core/types/type-helpers.js +1 -0
- package/dist/core/utils/predicate-builder.d.ts +12 -10
- package/dist/core/utils/predicate-builder.d.ts.map +1 -1
- package/dist/core/utils/predicate-builder.js +2 -1
- package/dist/core/utils/sql-expressions.d.ts +11 -10
- package/dist/core/utils/sql-expressions.d.ts.map +1 -1
- package/dist/core/utils/sql-expressions.js +4 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/types/schema.d.ts +1 -1
- package/dist/types/schema.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -184,9 +184,25 @@ const tripsWithDrivers = await db.table('trips')
|
|
|
184
184
|
.join('drivers', 'trips.driver_id', 'drivers.id')
|
|
185
185
|
.execute();
|
|
186
186
|
|
|
187
|
+
// After joining, TypeScript understands the expanded scope
|
|
188
|
+
const tripsWithUsers = await db.table('trips')
|
|
189
|
+
.innerJoin('users', 'trips.user_id', 'users.id')
|
|
190
|
+
.select(['users.email', 'trips.trip_id'])
|
|
191
|
+
.where('users.email', 'like', '%@example.com')
|
|
192
|
+
.execute();
|
|
193
|
+
|
|
194
|
+
// Keep literal column inference with selectConst and reuse joined columns in ORDER BY / HAVING
|
|
195
|
+
const sortedTrips = await db.table('trips')
|
|
196
|
+
.innerJoin('users', 'trips.user_id', 'users.id')
|
|
197
|
+
.selectConst('users.email', 'trips.trip_id')
|
|
198
|
+
.groupBy(['users.email', 'trips.trip_id'])
|
|
199
|
+
.having('COUNT(*) > 1')
|
|
200
|
+
.orderBy('users.email', 'DESC')
|
|
201
|
+
.execute();
|
|
187
202
|
|
|
188
203
|
```
|
|
189
204
|
|
|
205
|
+
`selectConst()` preserves literal column names (including aliases like `users.email`), which means TypeScript keeps those identifiers available for downstream `orderBy`, `groupBy`, and `having` calls.
|
|
190
206
|
|
|
191
207
|
**Benefits:**
|
|
192
208
|
- ✅ Works in all environments (Node.js, browser, bundlers)
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
+
import type { BuilderState, SchemaDefinition } from '../types/builder-state.js';
|
|
1
2
|
import { QueryBuilder } from '../query-builder.js';
|
|
2
|
-
|
|
3
|
-
export declare class AggregationFeature<Schema extends {
|
|
4
|
-
[tableName: string]: {
|
|
5
|
-
[columnName: string]: ColumnType;
|
|
6
|
-
};
|
|
7
|
-
}, T, HasSelect extends boolean = false, Aggregations = {}, OriginalT = T> {
|
|
3
|
+
export declare class AggregationFeature<Schema extends SchemaDefinition<Schema>, State extends BuilderState<Schema, string, any, keyof Schema, Partial<Record<string, keyof Schema>>>> {
|
|
8
4
|
private builder;
|
|
9
|
-
constructor(builder: QueryBuilder<Schema,
|
|
5
|
+
constructor(builder: QueryBuilder<Schema, State>);
|
|
10
6
|
private createAggregation;
|
|
11
|
-
sum
|
|
7
|
+
sum(column: string, alias: string): {
|
|
12
8
|
select: string[];
|
|
13
9
|
where?: import("../../types/base.js").WhereCondition[];
|
|
14
10
|
groupBy?: string[];
|
|
@@ -17,7 +13,7 @@ export declare class AggregationFeature<Schema extends {
|
|
|
17
13
|
offset?: number;
|
|
18
14
|
distinct?: boolean;
|
|
19
15
|
orderBy?: {
|
|
20
|
-
column: keyof
|
|
16
|
+
column: keyof State["output"] | import("../../index.js").TableColumn<Schema>;
|
|
21
17
|
direction: import("../../index.js").OrderDirection;
|
|
22
18
|
}[] | undefined;
|
|
23
19
|
joins?: import("../../types/base.js").JoinClause[];
|
|
@@ -26,7 +22,7 @@ export declare class AggregationFeature<Schema extends {
|
|
|
26
22
|
unionQueries?: string[];
|
|
27
23
|
settings?: string;
|
|
28
24
|
};
|
|
29
|
-
count
|
|
25
|
+
count(column: string, alias: string): {
|
|
30
26
|
select: string[];
|
|
31
27
|
where?: import("../../types/base.js").WhereCondition[];
|
|
32
28
|
groupBy?: string[];
|
|
@@ -35,7 +31,7 @@ export declare class AggregationFeature<Schema extends {
|
|
|
35
31
|
offset?: number;
|
|
36
32
|
distinct?: boolean;
|
|
37
33
|
orderBy?: {
|
|
38
|
-
column: keyof
|
|
34
|
+
column: keyof State["output"] | import("../../index.js").TableColumn<Schema>;
|
|
39
35
|
direction: import("../../index.js").OrderDirection;
|
|
40
36
|
}[] | undefined;
|
|
41
37
|
joins?: import("../../types/base.js").JoinClause[];
|
|
@@ -44,7 +40,7 @@ export declare class AggregationFeature<Schema extends {
|
|
|
44
40
|
unionQueries?: string[];
|
|
45
41
|
settings?: string;
|
|
46
42
|
};
|
|
47
|
-
avg
|
|
43
|
+
avg(column: string, alias: string): {
|
|
48
44
|
select: string[];
|
|
49
45
|
where?: import("../../types/base.js").WhereCondition[];
|
|
50
46
|
groupBy?: string[];
|
|
@@ -53,7 +49,7 @@ export declare class AggregationFeature<Schema extends {
|
|
|
53
49
|
offset?: number;
|
|
54
50
|
distinct?: boolean;
|
|
55
51
|
orderBy?: {
|
|
56
|
-
column: keyof
|
|
52
|
+
column: keyof State["output"] | import("../../index.js").TableColumn<Schema>;
|
|
57
53
|
direction: import("../../index.js").OrderDirection;
|
|
58
54
|
}[] | undefined;
|
|
59
55
|
joins?: import("../../types/base.js").JoinClause[];
|
|
@@ -62,7 +58,7 @@ export declare class AggregationFeature<Schema extends {
|
|
|
62
58
|
unionQueries?: string[];
|
|
63
59
|
settings?: string;
|
|
64
60
|
};
|
|
65
|
-
min
|
|
61
|
+
min(column: string, alias: string): {
|
|
66
62
|
select: string[];
|
|
67
63
|
where?: import("../../types/base.js").WhereCondition[];
|
|
68
64
|
groupBy?: string[];
|
|
@@ -71,7 +67,7 @@ export declare class AggregationFeature<Schema extends {
|
|
|
71
67
|
offset?: number;
|
|
72
68
|
distinct?: boolean;
|
|
73
69
|
orderBy?: {
|
|
74
|
-
column: keyof
|
|
70
|
+
column: keyof State["output"] | import("../../index.js").TableColumn<Schema>;
|
|
75
71
|
direction: import("../../index.js").OrderDirection;
|
|
76
72
|
}[] | undefined;
|
|
77
73
|
joins?: import("../../types/base.js").JoinClause[];
|
|
@@ -80,7 +76,7 @@ export declare class AggregationFeature<Schema extends {
|
|
|
80
76
|
unionQueries?: string[];
|
|
81
77
|
settings?: string;
|
|
82
78
|
};
|
|
83
|
-
max
|
|
79
|
+
max(column: string, alias: string): {
|
|
84
80
|
select: string[];
|
|
85
81
|
where?: import("../../types/base.js").WhereCondition[];
|
|
86
82
|
groupBy?: string[];
|
|
@@ -89,7 +85,7 @@ export declare class AggregationFeature<Schema extends {
|
|
|
89
85
|
offset?: number;
|
|
90
86
|
distinct?: boolean;
|
|
91
87
|
orderBy?: {
|
|
92
|
-
column: keyof
|
|
88
|
+
column: keyof State["output"] | import("../../index.js").TableColumn<Schema>;
|
|
93
89
|
direction: import("../../index.js").OrderDirection;
|
|
94
90
|
}[] | undefined;
|
|
95
91
|
joins?: import("../../types/base.js").JoinClause[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregations.d.ts","sourceRoot":"","sources":["../../../src/core/features/aggregations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"aggregations.d.ts","sourceRoot":"","sources":["../../../src/core/features/aggregations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,qBAAa,kBAAkB,CAC7B,MAAM,SAAS,gBAAgB,CAAC,MAAM,CAAC,EACvC,KAAK,SAAS,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC;IAExF,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC;IAExD,OAAO,CAAC,iBAAiB;IAsBzB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;;;;;;;;;;;;;;;IAIjC,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;;;;;;;;;;;;;;;IAInC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;;;;;;;;;;;;;;;IAIjC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;;;;;;;;;;;;;;;IAIjC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;;;;;;;;;;;;;;;CAGlC"}
|
|
@@ -4,7 +4,7 @@ export class AggregationFeature {
|
|
|
4
4
|
this.builder = builder;
|
|
5
5
|
}
|
|
6
6
|
createAggregation(column, fn, alias) {
|
|
7
|
-
const aggregationSQL = `${fn}(${
|
|
7
|
+
const aggregationSQL = `${fn}(${column}) AS ${alias}`;
|
|
8
8
|
const config = this.builder.getConfig();
|
|
9
9
|
if (config.select) {
|
|
10
10
|
return {
|
|
@@ -19,18 +19,18 @@ export class AggregationFeature {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
sum(column, alias) {
|
|
22
|
-
return this.createAggregation(column, 'SUM', alias
|
|
22
|
+
return this.createAggregation(column, 'SUM', alias);
|
|
23
23
|
}
|
|
24
24
|
count(column, alias) {
|
|
25
|
-
return this.createAggregation(column, 'COUNT', alias
|
|
25
|
+
return this.createAggregation(column, 'COUNT', alias);
|
|
26
26
|
}
|
|
27
27
|
avg(column, alias) {
|
|
28
|
-
return this.createAggregation(column, 'AVG', alias
|
|
28
|
+
return this.createAggregation(column, 'AVG', alias);
|
|
29
29
|
}
|
|
30
30
|
min(column, alias) {
|
|
31
|
-
return this.createAggregation(column, 'MIN', alias
|
|
31
|
+
return this.createAggregation(column, 'MIN', alias);
|
|
32
32
|
}
|
|
33
33
|
max(column, alias) {
|
|
34
|
-
return this.createAggregation(column, 'MAX', alias
|
|
34
|
+
return this.createAggregation(column, 'MAX', alias);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import { QueryBuilder } from '../query-builder.js';
|
|
2
|
-
import { ColumnType, TableColumn } from '../../types/schema.js';
|
|
3
1
|
import { ClickHouseSettings } from '@clickhouse/client-common';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
}, T, HasSelect extends boolean = false, Aggregations = {}, OriginalT = T> {
|
|
2
|
+
import type { AnyBuilderState, BuilderState, SchemaDefinition } from '../types/builder-state.js';
|
|
3
|
+
import { QueryBuilder } from '../query-builder.js';
|
|
4
|
+
export declare class AnalyticsFeature<Schema extends SchemaDefinition<Schema>, State extends BuilderState<Schema, string, any, keyof Schema, Partial<Record<string, keyof Schema>>>> {
|
|
9
5
|
private builder;
|
|
10
|
-
constructor(builder: QueryBuilder<Schema,
|
|
11
|
-
addCTE(alias: string, subquery: QueryBuilder<any,
|
|
6
|
+
constructor(builder: QueryBuilder<Schema, State>);
|
|
7
|
+
addCTE(alias: string, subquery: QueryBuilder<any, AnyBuilderState> | string): {
|
|
12
8
|
ctes: string[];
|
|
13
|
-
select?: (string | keyof
|
|
9
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
14
10
|
where?: import("../../types/base.js").WhereCondition[];
|
|
15
11
|
groupBy?: string[];
|
|
16
12
|
having?: string[];
|
|
@@ -18,7 +14,7 @@ export declare class AnalyticsFeature<Schema extends {
|
|
|
18
14
|
offset?: number;
|
|
19
15
|
distinct?: boolean;
|
|
20
16
|
orderBy?: {
|
|
21
|
-
column: keyof
|
|
17
|
+
column: keyof State["output"] | import("../../index.js").TableColumn<Schema>;
|
|
22
18
|
direction: import("../../index.js").OrderDirection;
|
|
23
19
|
}[] | undefined;
|
|
24
20
|
joins?: import("../../types/base.js").JoinClause[];
|
|
@@ -26,16 +22,16 @@ export declare class AnalyticsFeature<Schema extends {
|
|
|
26
22
|
unionQueries?: string[];
|
|
27
23
|
settings?: string;
|
|
28
24
|
};
|
|
29
|
-
addTimeInterval(column:
|
|
25
|
+
addTimeInterval(column: string, interval: string, method: 'toStartOfInterval' | 'toStartOfMinute' | 'toStartOfHour' | 'toStartOfDay' | 'toStartOfWeek' | 'toStartOfMonth' | 'toStartOfQuarter' | 'toStartOfYear'): {
|
|
30
26
|
groupBy: string[];
|
|
31
|
-
select?: (string | keyof
|
|
27
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
32
28
|
where?: import("../../types/base.js").WhereCondition[];
|
|
33
29
|
having?: string[];
|
|
34
30
|
limit?: number;
|
|
35
31
|
offset?: number;
|
|
36
32
|
distinct?: boolean;
|
|
37
33
|
orderBy?: {
|
|
38
|
-
column: keyof
|
|
34
|
+
column: keyof State["output"] | import("../../index.js").TableColumn<Schema>;
|
|
39
35
|
direction: import("../../index.js").OrderDirection;
|
|
40
36
|
}[] | undefined;
|
|
41
37
|
joins?: import("../../types/base.js").JoinClause[];
|
|
@@ -46,7 +42,7 @@ export declare class AnalyticsFeature<Schema extends {
|
|
|
46
42
|
};
|
|
47
43
|
addSettings(opts: ClickHouseSettings): {
|
|
48
44
|
settings: string;
|
|
49
|
-
select?: (string | keyof
|
|
45
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
50
46
|
where?: import("../../types/base.js").WhereCondition[];
|
|
51
47
|
groupBy?: string[];
|
|
52
48
|
having?: string[];
|
|
@@ -54,7 +50,7 @@ export declare class AnalyticsFeature<Schema extends {
|
|
|
54
50
|
offset?: number;
|
|
55
51
|
distinct?: boolean;
|
|
56
52
|
orderBy?: {
|
|
57
|
-
column: keyof
|
|
53
|
+
column: keyof State["output"] | import("../../index.js").TableColumn<Schema>;
|
|
58
54
|
direction: import("../../index.js").OrderDirection;
|
|
59
55
|
}[] | undefined;
|
|
60
56
|
joins?: import("../../types/base.js").JoinClause[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../../src/core/features/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../../src/core/features/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACjG,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,qBAAa,gBAAgB,CAC3B,MAAM,SAAS,gBAAgB,CAAC,MAAM,CAAC,EACvC,KAAK,SAAS,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC;IAExF,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC;IAExD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,CAAC,GAAG,EAAE,eAAe,CAAC,GAAG,MAAM;;;;;;;;;;;;;;;;;;IAS3E,eAAe,CACb,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,mBAAmB,GAAG,iBAAiB,GAAG,eAAe,GAAG,cAAc,GAAG,eAAe,GAAG,gBAAgB,GAAG,kBAAkB,GAAG,eAAe;;;;;;;;;;;;;;;;;;IAiBhK,WAAW,CAAC,IAAI,EAAE,kBAAkB;;;;;;;;;;;;;;;;;;CAQrC"}
|
|
@@ -15,10 +15,10 @@ export class AnalyticsFeature {
|
|
|
15
15
|
const config = this.builder.getConfig();
|
|
16
16
|
const groupBy = config.groupBy || [];
|
|
17
17
|
if (method === 'toStartOfInterval') {
|
|
18
|
-
groupBy.push(`${method}(${
|
|
18
|
+
groupBy.push(`${method}(${column}, INTERVAL ${interval})`);
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
|
-
groupBy.push(`${method}(${
|
|
21
|
+
groupBy.push(`${method}(${column})`);
|
|
22
22
|
}
|
|
23
23
|
return {
|
|
24
24
|
...config,
|
|
@@ -1,27 +1,12 @@
|
|
|
1
|
+
import type { BuilderState } from '../types/builder-state.js';
|
|
1
2
|
import { QueryBuilder } from '../query-builder.js';
|
|
2
3
|
import { CrossFilter } from '../cross-filter.js';
|
|
3
4
|
import { AnySchema } from '../../types/schema.js';
|
|
4
|
-
|
|
5
|
-
* Feature for handling cross-filter operations on queries
|
|
6
|
-
*/
|
|
7
|
-
export declare class CrossFilteringFeature<Schema extends AnySchema, T, HasSelect extends boolean = false, Aggregations = {}, OriginalT = T> {
|
|
5
|
+
export declare class CrossFilteringFeature<Schema extends AnySchema, State extends BuilderState<Schema, string, any, keyof Schema, Partial<Record<string, keyof Schema>>>> {
|
|
8
6
|
private builder;
|
|
9
|
-
constructor(builder: QueryBuilder<Schema,
|
|
10
|
-
|
|
11
|
-
* Applies a set of cross filters to the query
|
|
12
|
-
* @param crossFilter - An instance of CrossFilter containing shared filter conditions
|
|
13
|
-
* @returns Updated query config
|
|
14
|
-
*/
|
|
15
|
-
applyCrossFilters(crossFilter: CrossFilter<Schema, Extract<keyof Schema, string>>): import("../../types/base.js").QueryConfig<T, Schema>;
|
|
16
|
-
/**
|
|
17
|
-
* Apply AND conditions - each condition is applied with WHERE
|
|
18
|
-
*/
|
|
7
|
+
constructor(builder: QueryBuilder<Schema, State>);
|
|
8
|
+
applyCrossFilters(crossFilter: CrossFilter<Schema, Extract<keyof Schema, string>>): import("../../types/base.js").QueryConfig<State["output"], Schema>;
|
|
19
9
|
private applyAndConditions;
|
|
20
|
-
/**
|
|
21
|
-
* Apply direct OR conditions without adding extra conjunctions
|
|
22
|
-
* @param conditions The conditions to apply
|
|
23
|
-
* @param builder The builder to apply conditions to, defaults to this.builder
|
|
24
|
-
*/
|
|
25
10
|
private applyOrConditions;
|
|
26
11
|
}
|
|
27
12
|
//# sourceMappingURL=cross-filtering.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cross-filtering.d.ts","sourceRoot":"","sources":["../../../src/core/features/cross-filtering.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAe,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"cross-filtering.d.ts","sourceRoot":"","sources":["../../../src/core/features/cross-filtering.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAe,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAUlD,qBAAa,qBAAqB,CAChC,MAAM,SAAS,SAAS,EACxB,KAAK,SAAS,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC;IAExF,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC;IAExD,iBAAiB,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,MAAM,EAAE,MAAM,CAAC,CAAC;IAkBjF,OAAO,CAAC,kBAAkB;IAwB1B,OAAO,CAAC,iBAAiB;CAkD1B"}
|
|
@@ -1,68 +1,43 @@
|
|
|
1
1
|
//@ts-
|
|
2
|
-
/**
|
|
3
|
-
* Type guard to check if an object is a FilterConditionInput
|
|
4
|
-
*/
|
|
5
2
|
function isFilterCondition(obj) {
|
|
6
3
|
return obj && 'column' in obj && 'operator' in obj && 'value' in obj;
|
|
7
4
|
}
|
|
8
|
-
/**
|
|
9
|
-
* Type guard to check if an object is a FilterGroup
|
|
10
|
-
*/
|
|
11
5
|
function isFilterGroup(obj) {
|
|
12
6
|
return obj && 'conditions' in obj && 'operator' in obj;
|
|
13
7
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Feature for handling cross-filter operations on queries
|
|
16
|
-
*/
|
|
17
8
|
export class CrossFilteringFeature {
|
|
18
9
|
builder;
|
|
19
10
|
constructor(builder) {
|
|
20
11
|
this.builder = builder;
|
|
21
12
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Applies a set of cross filters to the query
|
|
24
|
-
* @param crossFilter - An instance of CrossFilter containing shared filter conditions
|
|
25
|
-
* @returns Updated query config
|
|
26
|
-
*/
|
|
27
13
|
applyCrossFilters(crossFilter) {
|
|
28
14
|
const filterGroup = crossFilter.getConditions();
|
|
29
15
|
if (filterGroup.conditions.length === 0) {
|
|
30
16
|
return this.builder.getConfig();
|
|
31
17
|
}
|
|
32
|
-
// Apply conditions based on filter group operator
|
|
33
18
|
if (filterGroup.operator === 'AND') {
|
|
34
|
-
// For AND groups, apply each condition directly
|
|
35
19
|
this.applyAndConditions(filterGroup.conditions);
|
|
36
20
|
}
|
|
37
21
|
else {
|
|
38
|
-
// For OR groups, special handling to ensure proper parentheses
|
|
39
|
-
// We use whereGroup instead of orWhereGroup here since this is a top-level group
|
|
40
22
|
this.builder.whereGroup(builder => {
|
|
41
23
|
this.applyOrConditions(filterGroup.conditions, builder);
|
|
42
24
|
});
|
|
43
25
|
}
|
|
44
26
|
return this.builder.getConfig();
|
|
45
27
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Apply AND conditions - each condition is applied with WHERE
|
|
48
|
-
*/
|
|
49
28
|
applyAndConditions(conditions) {
|
|
50
29
|
conditions.forEach(condition => {
|
|
51
30
|
if (isFilterCondition(condition)) {
|
|
52
|
-
// Simple condition - apply with WHERE
|
|
53
31
|
this.builder.where(condition.column, condition.operator, condition.value);
|
|
54
32
|
}
|
|
55
33
|
else if (isFilterGroup(condition)) {
|
|
56
|
-
// Nested group
|
|
57
34
|
if (condition.operator === 'AND') {
|
|
58
|
-
// AND subgroup - apply all conditions
|
|
59
35
|
this.builder.whereGroup(builder => {
|
|
60
36
|
const feature = new CrossFilteringFeature(builder);
|
|
61
37
|
feature.applyAndConditions(condition.conditions);
|
|
62
38
|
});
|
|
63
39
|
}
|
|
64
40
|
else {
|
|
65
|
-
// OR subgroup within AND - needs special parentheses handling
|
|
66
41
|
this.builder.whereGroup(builder => {
|
|
67
42
|
const feature = new CrossFilteringFeature(builder);
|
|
68
43
|
feature.applyOrConditions(condition.conditions, builder);
|
|
@@ -71,21 +46,14 @@ export class CrossFilteringFeature {
|
|
|
71
46
|
}
|
|
72
47
|
});
|
|
73
48
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Apply direct OR conditions without adding extra conjunctions
|
|
76
|
-
* @param conditions The conditions to apply
|
|
77
|
-
* @param builder The builder to apply conditions to, defaults to this.builder
|
|
78
|
-
*/
|
|
79
49
|
applyOrConditions(conditions, builder = this.builder) {
|
|
80
50
|
if (conditions.length === 0)
|
|
81
51
|
return;
|
|
82
|
-
// Handle first condition
|
|
83
52
|
const firstCondition = conditions[0];
|
|
84
53
|
if (isFilterCondition(firstCondition)) {
|
|
85
54
|
builder.where(firstCondition.column, firstCondition.operator, firstCondition.value);
|
|
86
55
|
}
|
|
87
56
|
else if (isFilterGroup(firstCondition)) {
|
|
88
|
-
// Handle nested group
|
|
89
57
|
if (firstCondition.operator === 'AND') {
|
|
90
58
|
builder.whereGroup(innerBuilder => {
|
|
91
59
|
const feature = new CrossFilteringFeature(innerBuilder);
|
|
@@ -99,7 +67,6 @@ export class CrossFilteringFeature {
|
|
|
99
67
|
});
|
|
100
68
|
}
|
|
101
69
|
}
|
|
102
|
-
// Handle remaining conditions
|
|
103
70
|
for (let i = 1; i < conditions.length; i++) {
|
|
104
71
|
const condition = conditions[i];
|
|
105
72
|
if (isFilterCondition(condition)) {
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
+
import type { BuilderState, SchemaDefinition } from '../types/builder-state.js';
|
|
1
2
|
import { QueryBuilder } from '../query-builder.js';
|
|
2
|
-
|
|
3
|
-
export declare class ExecutorFeature<Schema extends {
|
|
4
|
-
[tableName: string]: {
|
|
5
|
-
[columnName: string]: ColumnType;
|
|
6
|
-
};
|
|
7
|
-
}, T, HasSelect extends boolean = false, Aggregations = {}, OriginalT = T> {
|
|
3
|
+
export declare class ExecutorFeature<Schema extends SchemaDefinition<Schema>, State extends BuilderState<Schema, string, any, keyof Schema, Partial<Record<string, keyof Schema>>>> {
|
|
8
4
|
private builder;
|
|
9
|
-
constructor(builder: QueryBuilder<Schema,
|
|
5
|
+
constructor(builder: QueryBuilder<Schema, State>);
|
|
10
6
|
toSQLWithParams(): {
|
|
11
7
|
sql: string;
|
|
12
8
|
parameters: any[];
|
|
13
9
|
};
|
|
14
10
|
toSQL(): string;
|
|
15
|
-
execute(): Promise<
|
|
16
|
-
stream(): Promise<ReadableStream<
|
|
11
|
+
execute(): Promise<State['output'][]>;
|
|
12
|
+
stream(): Promise<ReadableStream<State['output'][]>>;
|
|
17
13
|
private toSQLWithoutParameters;
|
|
18
14
|
}
|
|
19
15
|
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/core/features/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/core/features/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAKnD,qBAAa,eAAe,CAC1B,MAAM,SAAS,gBAAgB,CAAC,MAAM,CAAC,EACvC,KAAK,SAAS,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC;IAExF,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC;IAExD,eAAe,IAAI;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,GAAG,EAAE,CAAA;KAAE;IAOrD,KAAK,IAAI,MAAM;IAKT,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;IAgDrC,MAAM,IAAI,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IA+C1D,OAAO,CAAC,sBAAsB;CA0C/B"}
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
+
import type { BuilderState, SchemaDefinition } from '../types/builder-state.js';
|
|
1
2
|
import { QueryBuilder } from '../query-builder.js';
|
|
2
3
|
import { FilterOperator } from '../../types/index.js';
|
|
3
|
-
import { ColumnType, TableColumn } from '../../types/schema.js';
|
|
4
4
|
import { PredicateExpression } from '../utils/predicate-builder.js';
|
|
5
|
-
export declare class FilteringFeature<Schema extends {
|
|
6
|
-
[tableName: string]: {
|
|
7
|
-
[columnName: string]: ColumnType;
|
|
8
|
-
};
|
|
9
|
-
}, T, HasSelect extends boolean = false, Aggregations = {}, OriginalT = T> {
|
|
5
|
+
export declare class FilteringFeature<Schema extends SchemaDefinition<Schema>, State extends BuilderState<Schema, string, any, keyof Schema, Partial<Record<string, keyof Schema>>>> {
|
|
10
6
|
private builder;
|
|
11
|
-
constructor(builder: QueryBuilder<Schema,
|
|
12
|
-
addCondition
|
|
7
|
+
constructor(builder: QueryBuilder<Schema, State>);
|
|
8
|
+
addCondition(conjunction: 'AND' | 'OR', column: string | string[], operator: FilterOperator, value: any): {
|
|
13
9
|
where: import("../../types/base.js").WhereCondition[];
|
|
14
10
|
parameters: any[];
|
|
15
|
-
select?: (string | keyof
|
|
11
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
16
12
|
groupBy?: string[];
|
|
17
13
|
having?: string[];
|
|
18
14
|
limit?: number;
|
|
19
15
|
offset?: number;
|
|
20
16
|
distinct?: boolean;
|
|
21
17
|
orderBy?: {
|
|
22
|
-
column: TableColumn<Schema
|
|
18
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
23
19
|
direction: import("../../types/base.js").OrderDirection;
|
|
24
20
|
}[] | undefined;
|
|
25
21
|
joins?: import("../../types/base.js").JoinClause[];
|
|
@@ -30,14 +26,14 @@ export declare class FilteringFeature<Schema extends {
|
|
|
30
26
|
addExpressionCondition(conjunction: 'AND' | 'OR', expression: PredicateExpression): {
|
|
31
27
|
where: import("../../types/base.js").WhereCondition[];
|
|
32
28
|
parameters: any[];
|
|
33
|
-
select?: (string | keyof
|
|
29
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
34
30
|
groupBy?: string[];
|
|
35
31
|
having?: string[];
|
|
36
32
|
limit?: number;
|
|
37
33
|
offset?: number;
|
|
38
34
|
distinct?: boolean;
|
|
39
35
|
orderBy?: {
|
|
40
|
-
column: TableColumn<Schema
|
|
36
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
41
37
|
direction: import("../../types/base.js").OrderDirection;
|
|
42
38
|
}[] | undefined;
|
|
43
39
|
joins?: import("../../types/base.js").JoinClause[];
|
|
@@ -45,20 +41,16 @@ export declare class FilteringFeature<Schema extends {
|
|
|
45
41
|
unionQueries?: string[];
|
|
46
42
|
settings?: string;
|
|
47
43
|
};
|
|
48
|
-
/**
|
|
49
|
-
* Adds a group-start marker to start a parenthesized group of conditions with AND conjunction
|
|
50
|
-
* @returns The updated query config
|
|
51
|
-
*/
|
|
52
44
|
startWhereGroup(): {
|
|
53
45
|
where: import("../../types/base.js").WhereCondition[];
|
|
54
|
-
select?: (string | keyof
|
|
46
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
55
47
|
groupBy?: string[];
|
|
56
48
|
having?: string[];
|
|
57
49
|
limit?: number;
|
|
58
50
|
offset?: number;
|
|
59
51
|
distinct?: boolean;
|
|
60
52
|
orderBy?: {
|
|
61
|
-
column: TableColumn<Schema
|
|
53
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
62
54
|
direction: import("../../types/base.js").OrderDirection;
|
|
63
55
|
}[] | undefined;
|
|
64
56
|
joins?: import("../../types/base.js").JoinClause[];
|
|
@@ -67,20 +59,16 @@ export declare class FilteringFeature<Schema extends {
|
|
|
67
59
|
unionQueries?: string[];
|
|
68
60
|
settings?: string;
|
|
69
61
|
};
|
|
70
|
-
/**
|
|
71
|
-
* Adds a group-start marker to start a parenthesized group of conditions with OR conjunction
|
|
72
|
-
* @returns The updated query config
|
|
73
|
-
*/
|
|
74
62
|
startOrWhereGroup(): {
|
|
75
63
|
where: import("../../types/base.js").WhereCondition[];
|
|
76
|
-
select?: (string | keyof
|
|
64
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
77
65
|
groupBy?: string[];
|
|
78
66
|
having?: string[];
|
|
79
67
|
limit?: number;
|
|
80
68
|
offset?: number;
|
|
81
69
|
distinct?: boolean;
|
|
82
70
|
orderBy?: {
|
|
83
|
-
column: TableColumn<Schema
|
|
71
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
84
72
|
direction: import("../../types/base.js").OrderDirection;
|
|
85
73
|
}[] | undefined;
|
|
86
74
|
joins?: import("../../types/base.js").JoinClause[];
|
|
@@ -89,20 +77,16 @@ export declare class FilteringFeature<Schema extends {
|
|
|
89
77
|
unionQueries?: string[];
|
|
90
78
|
settings?: string;
|
|
91
79
|
};
|
|
92
|
-
/**
|
|
93
|
-
* Adds a group-end marker to end a parenthesized group of conditions
|
|
94
|
-
* @returns The updated query config
|
|
95
|
-
*/
|
|
96
80
|
endWhereGroup(): {
|
|
97
81
|
where: import("../../types/base.js").WhereCondition[];
|
|
98
|
-
select?: (string | keyof
|
|
82
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
99
83
|
groupBy?: string[];
|
|
100
84
|
having?: string[];
|
|
101
85
|
limit?: number;
|
|
102
86
|
offset?: number;
|
|
103
87
|
distinct?: boolean;
|
|
104
88
|
orderBy?: {
|
|
105
|
-
column: TableColumn<Schema
|
|
89
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
106
90
|
direction: import("../../types/base.js").OrderDirection;
|
|
107
91
|
}[] | undefined;
|
|
108
92
|
joins?: import("../../types/base.js").JoinClause[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../../../src/core/features/filtering.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../../../src/core/features/filtering.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEpE,qBAAa,gBAAgB,CAC3B,MAAM,SAAS,gBAAgB,CAAC,MAAM,CAAC,EACvC,KAAK,SAAS,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC;IAExF,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC;IAExD,YAAY,CACV,WAAW,EAAE,KAAK,GAAG,IAAI,EACzB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EACzB,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,GAAG;;;;;;;;;;;;;;;;;;IAwDZ,sBAAsB,CACpB,WAAW,EAAE,KAAK,GAAG,IAAI,EACzB,UAAU,EAAE,mBAAmB;;;;;;;;;;;;;;;;;;IAsBjC,eAAe;;;;;;;;;;;;;;;;;;IAkBf,iBAAiB;;;;;;;;;;;;;;;;;;IAkBjB,aAAa;;;;;;;;;;;;;;;;;;CAiBd"}
|