@hypequery/clickhouse 0.0.0-canary-20260306132943
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/LICENSE +201 -0
- package/README-CLI.md +123 -0
- package/README.md +316 -0
- package/dist/cli/bin.js +285 -0
- package/dist/cli/generate-types.d.ts +5 -0
- package/dist/cli/generate-types.js +218 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +2 -0
- package/dist/core/cache/cache-manager.d.ts +4 -0
- package/dist/core/cache/cache-manager.d.ts.map +1 -0
- package/dist/core/cache/cache-manager.js +176 -0
- package/dist/core/cache/controller.d.ts +15 -0
- package/dist/core/cache/controller.d.ts.map +1 -0
- package/dist/core/cache/controller.js +58 -0
- package/dist/core/cache/key.d.ts +11 -0
- package/dist/core/cache/key.d.ts.map +1 -0
- package/dist/core/cache/key.js +26 -0
- package/dist/core/cache/providers/memory-lru.d.ts +31 -0
- package/dist/core/cache/providers/memory-lru.d.ts.map +1 -0
- package/dist/core/cache/providers/memory-lru.js +156 -0
- package/dist/core/cache/providers/noop.d.ts +7 -0
- package/dist/core/cache/providers/noop.d.ts.map +1 -0
- package/dist/core/cache/providers/noop.js +11 -0
- package/dist/core/cache/runtime-context.d.ts +30 -0
- package/dist/core/cache/runtime-context.d.ts.map +1 -0
- package/dist/core/cache/runtime-context.js +58 -0
- package/dist/core/cache/serialization.d.ts +6 -0
- package/dist/core/cache/serialization.d.ts.map +1 -0
- package/dist/core/cache/serialization.js +166 -0
- package/dist/core/cache/types.d.ts +52 -0
- package/dist/core/cache/types.d.ts.map +1 -0
- package/dist/core/cache/types.js +1 -0
- package/dist/core/cache/utils.d.ts +9 -0
- package/dist/core/cache/utils.d.ts.map +1 -0
- package/dist/core/cache/utils.js +30 -0
- package/dist/core/connection.d.ts +112 -0
- package/dist/core/connection.d.ts.map +1 -0
- package/dist/core/connection.js +150 -0
- package/dist/core/cross-filter.d.ts +73 -0
- package/dist/core/cross-filter.d.ts.map +1 -0
- package/dist/core/cross-filter.js +142 -0
- package/dist/core/env/auto-client.browser.d.ts +3 -0
- package/dist/core/env/auto-client.browser.d.ts.map +1 -0
- package/dist/core/env/auto-client.browser.js +3 -0
- package/dist/core/env/auto-client.d.ts +9 -0
- package/dist/core/env/auto-client.d.ts.map +1 -0
- package/dist/core/env/auto-client.js +21 -0
- package/dist/core/features/aggregations.d.ts +98 -0
- package/dist/core/features/aggregations.d.ts.map +1 -0
- package/dist/core/features/aggregations.js +36 -0
- package/dist/core/features/analytics.d.ts +81 -0
- package/dist/core/features/analytics.d.ts.map +1 -0
- package/dist/core/features/analytics.js +45 -0
- package/dist/core/features/cross-filtering.d.ts +11 -0
- package/dist/core/features/cross-filtering.d.ts.map +1 -0
- package/dist/core/features/cross-filtering.js +90 -0
- package/dist/core/features/executor.d.ts +21 -0
- package/dist/core/features/executor.d.ts.map +1 -0
- package/dist/core/features/executor.js +146 -0
- package/dist/core/features/filtering.d.ts +99 -0
- package/dist/core/features/filtering.d.ts.map +1 -0
- package/dist/core/features/filtering.js +118 -0
- package/dist/core/features/joins.d.ts +26 -0
- package/dist/core/features/joins.d.ts.map +1 -0
- package/dist/core/features/joins.js +17 -0
- package/dist/core/features/query-modifiers.d.ts +116 -0
- package/dist/core/features/query-modifiers.d.ts.map +1 -0
- package/dist/core/features/query-modifiers.js +51 -0
- package/dist/core/formatters/sql-formatter.d.ts +9 -0
- package/dist/core/formatters/sql-formatter.d.ts.map +1 -0
- package/dist/core/formatters/sql-formatter.js +131 -0
- package/dist/core/join-relationships.d.ts +51 -0
- package/dist/core/join-relationships.d.ts.map +1 -0
- package/dist/core/join-relationships.js +54 -0
- package/dist/core/query-builder.d.ts +236 -0
- package/dist/core/query-builder.d.ts.map +1 -0
- package/dist/core/query-builder.js +495 -0
- package/dist/core/tests/index.d.ts +2 -0
- package/dist/core/tests/index.d.ts.map +1 -0
- package/dist/core/tests/index.js +1 -0
- package/dist/core/tests/integration/setup.d.ts +48 -0
- package/dist/core/tests/integration/setup.d.ts.map +1 -0
- package/dist/core/tests/integration/setup.js +349 -0
- 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 +14 -0
- package/dist/core/tests/integration/test-data.json +190 -0
- package/dist/core/tests/test-utils.d.ts +44 -0
- package/dist/core/tests/test-utils.d.ts.map +1 -0
- package/dist/core/tests/test-utils.js +65 -0
- package/dist/core/types/builder-state.d.ts +27 -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 +33 -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/logger.d.ts +43 -0
- package/dist/core/utils/logger.d.ts.map +1 -0
- package/dist/core/utils/logger.js +104 -0
- package/dist/core/utils/predicate-builder.d.ts +33 -0
- package/dist/core/utils/predicate-builder.d.ts.map +1 -0
- package/dist/core/utils/predicate-builder.js +95 -0
- package/dist/core/utils/sql-expressions.d.ts +77 -0
- package/dist/core/utils/sql-expressions.d.ts.map +1 -0
- package/dist/core/utils/sql-expressions.js +54 -0
- package/dist/core/utils/streaming-helpers.d.ts +2 -0
- package/dist/core/utils/streaming-helpers.d.ts.map +1 -0
- package/dist/core/utils/streaming-helpers.js +137 -0
- package/dist/core/utils.d.ts +3 -0
- package/dist/core/utils.d.ts.map +1 -0
- package/dist/core/utils.js +29 -0
- package/dist/core/validators/filter-validator.d.ts +9 -0
- package/dist/core/validators/filter-validator.d.ts.map +1 -0
- package/dist/core/validators/filter-validator.js +19 -0
- package/dist/core/validators/value-validator.d.ts +7 -0
- package/dist/core/validators/value-validator.d.ts.map +1 -0
- package/dist/core/validators/value-validator.js +47 -0
- package/dist/formatters/index.d.ts +2 -0
- package/dist/formatters/index.d.ts.map +1 -0
- package/dist/formatters/index.js +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/types/base.d.ts +50 -0
- package/dist/types/base.d.ts.map +1 -0
- package/dist/types/base.js +1 -0
- package/dist/types/clickhouse-types.d.ts +17 -0
- package/dist/types/clickhouse-types.d.ts.map +1 -0
- package/dist/types/clickhouse-types.js +1 -0
- package/dist/types/filters.d.ts +53 -0
- package/dist/types/filters.d.ts.map +1 -0
- package/dist/types/filters.js +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/schema.d.ts +19 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/schema.js +1 -0
- package/package.json +90 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { ClickHouseConnection } from '../connection.js';
|
|
2
|
+
import { substituteParameters } from '../utils.js';
|
|
3
|
+
import { logger } from '../utils/logger.js';
|
|
4
|
+
import { createJsonEachRowStream } from '../utils/streaming-helpers.js';
|
|
5
|
+
export class ExecutorFeature {
|
|
6
|
+
builder;
|
|
7
|
+
constructor(builder) {
|
|
8
|
+
this.builder = builder;
|
|
9
|
+
}
|
|
10
|
+
toSQLWithParams() {
|
|
11
|
+
const sql = this.toSQLWithoutParameters();
|
|
12
|
+
const config = this.builder.getConfig();
|
|
13
|
+
const parameters = config.parameters || [];
|
|
14
|
+
return { sql, parameters };
|
|
15
|
+
}
|
|
16
|
+
toSQL() {
|
|
17
|
+
const { sql, parameters } = this.toSQLWithParams();
|
|
18
|
+
return substituteParameters(sql, parameters);
|
|
19
|
+
}
|
|
20
|
+
async execute(options) {
|
|
21
|
+
const client = ClickHouseConnection.getClient();
|
|
22
|
+
const { sql, parameters } = this.toSQLWithParams();
|
|
23
|
+
const finalSQL = substituteParameters(sql, parameters);
|
|
24
|
+
const startTime = Date.now();
|
|
25
|
+
logger.logQuery({
|
|
26
|
+
query: finalSQL,
|
|
27
|
+
parameters,
|
|
28
|
+
startTime,
|
|
29
|
+
status: 'started',
|
|
30
|
+
queryId: options?.queryId,
|
|
31
|
+
...options?.logContext
|
|
32
|
+
});
|
|
33
|
+
try {
|
|
34
|
+
const result = await client.query({
|
|
35
|
+
query: finalSQL,
|
|
36
|
+
format: 'JSONEachRow'
|
|
37
|
+
});
|
|
38
|
+
const rows = await result.json();
|
|
39
|
+
const endTime = Date.now();
|
|
40
|
+
logger.logQuery({
|
|
41
|
+
query: finalSQL,
|
|
42
|
+
parameters,
|
|
43
|
+
startTime,
|
|
44
|
+
endTime,
|
|
45
|
+
duration: endTime - startTime,
|
|
46
|
+
status: 'completed',
|
|
47
|
+
rowCount: rows.length,
|
|
48
|
+
queryId: options?.queryId,
|
|
49
|
+
cacheRowCount: rows.length,
|
|
50
|
+
...options?.logContext
|
|
51
|
+
});
|
|
52
|
+
return rows;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
const endTime = Date.now();
|
|
56
|
+
logger.logQuery({
|
|
57
|
+
query: finalSQL,
|
|
58
|
+
parameters,
|
|
59
|
+
startTime,
|
|
60
|
+
endTime,
|
|
61
|
+
duration: endTime - startTime,
|
|
62
|
+
status: 'error',
|
|
63
|
+
error: error,
|
|
64
|
+
queryId: options?.queryId,
|
|
65
|
+
...options?.logContext
|
|
66
|
+
});
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async stream() {
|
|
71
|
+
const client = ClickHouseConnection.getClient();
|
|
72
|
+
const { sql, parameters } = this.toSQLWithParams();
|
|
73
|
+
const finalSQL = substituteParameters(sql, parameters);
|
|
74
|
+
const startTime = Date.now();
|
|
75
|
+
logger.logQuery({
|
|
76
|
+
query: finalSQL,
|
|
77
|
+
parameters,
|
|
78
|
+
startTime,
|
|
79
|
+
status: 'started'
|
|
80
|
+
});
|
|
81
|
+
try {
|
|
82
|
+
const result = await client.query({
|
|
83
|
+
query: finalSQL,
|
|
84
|
+
format: 'JSONEachRow'
|
|
85
|
+
});
|
|
86
|
+
const stream = result.stream();
|
|
87
|
+
const webStream = createJsonEachRowStream(stream);
|
|
88
|
+
const endTime = Date.now();
|
|
89
|
+
logger.logQuery({
|
|
90
|
+
query: finalSQL,
|
|
91
|
+
parameters,
|
|
92
|
+
startTime,
|
|
93
|
+
endTime,
|
|
94
|
+
duration: endTime - startTime,
|
|
95
|
+
status: 'completed'
|
|
96
|
+
});
|
|
97
|
+
return webStream;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
const endTime = Date.now();
|
|
101
|
+
logger.logQuery({
|
|
102
|
+
query: finalSQL,
|
|
103
|
+
parameters,
|
|
104
|
+
startTime,
|
|
105
|
+
endTime,
|
|
106
|
+
duration: endTime - startTime,
|
|
107
|
+
status: 'error',
|
|
108
|
+
error: error
|
|
109
|
+
});
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
toSQLWithoutParameters() {
|
|
114
|
+
const config = this.builder.getConfig();
|
|
115
|
+
const formatter = this.builder.getFormatter();
|
|
116
|
+
const parts = [];
|
|
117
|
+
if (config.ctes?.length) {
|
|
118
|
+
parts.push(`WITH ${config.ctes.join(', ')}`);
|
|
119
|
+
}
|
|
120
|
+
parts.push(`SELECT ${formatter.formatSelect(config)}`);
|
|
121
|
+
parts.push(`FROM ${this.builder.getTableName()}`);
|
|
122
|
+
if (config.joins?.length) {
|
|
123
|
+
parts.push(formatter.formatJoins(config));
|
|
124
|
+
}
|
|
125
|
+
if (config.where?.length) {
|
|
126
|
+
parts.push(`WHERE ${formatter.formatWhere(config)}`);
|
|
127
|
+
}
|
|
128
|
+
if (config.groupBy?.length) {
|
|
129
|
+
parts.push(`GROUP BY ${formatter.formatGroupBy(config)}`);
|
|
130
|
+
}
|
|
131
|
+
if (config.having?.length) {
|
|
132
|
+
parts.push(`HAVING ${config.having.join(' AND ')}`);
|
|
133
|
+
}
|
|
134
|
+
if (config.orderBy?.length) {
|
|
135
|
+
const orderBy = config.orderBy
|
|
136
|
+
.map(({ column, direction }) => `${String(column)} ${direction}`.trim())
|
|
137
|
+
.join(', ');
|
|
138
|
+
parts.push(`ORDER BY ${orderBy}`);
|
|
139
|
+
}
|
|
140
|
+
if (config.limit) {
|
|
141
|
+
const offsetClause = config.offset ? `OFFSET ${config.offset}` : '';
|
|
142
|
+
parts.push(`LIMIT ${config.limit} ${offsetClause}`);
|
|
143
|
+
}
|
|
144
|
+
return parts.join(' ').trim();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { BuilderState, SchemaDefinition } from '../types/builder-state.js';
|
|
2
|
+
import { QueryBuilder } from '../query-builder.js';
|
|
3
|
+
import { FilterOperator } from '../../types/index.js';
|
|
4
|
+
import { PredicateExpression } from '../utils/predicate-builder.js';
|
|
5
|
+
export declare class FilteringFeature<Schema extends SchemaDefinition<Schema>, State extends BuilderState<Schema, string, any, keyof Schema, Partial<Record<string, keyof Schema>>>> {
|
|
6
|
+
private builder;
|
|
7
|
+
constructor(builder: QueryBuilder<Schema, State>);
|
|
8
|
+
addCondition(conjunction: 'AND' | 'OR', column: string | string[], operator: FilterOperator, value: any): {
|
|
9
|
+
where: import("../../types/base.js").WhereCondition[];
|
|
10
|
+
parameters: any[];
|
|
11
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
12
|
+
groupBy?: string[];
|
|
13
|
+
having?: string[];
|
|
14
|
+
limit?: number;
|
|
15
|
+
offset?: number;
|
|
16
|
+
distinct?: boolean;
|
|
17
|
+
orderBy?: {
|
|
18
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
19
|
+
direction: import("../../types/base.js").OrderDirection;
|
|
20
|
+
}[] | undefined;
|
|
21
|
+
joins?: import("../../types/base.js").JoinClause[];
|
|
22
|
+
ctes?: string[];
|
|
23
|
+
unionQueries?: string[];
|
|
24
|
+
settings?: string;
|
|
25
|
+
};
|
|
26
|
+
addExpressionCondition(conjunction: 'AND' | 'OR', expression: PredicateExpression): {
|
|
27
|
+
where: import("../../types/base.js").WhereCondition[];
|
|
28
|
+
parameters: any[];
|
|
29
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
30
|
+
groupBy?: string[];
|
|
31
|
+
having?: string[];
|
|
32
|
+
limit?: number;
|
|
33
|
+
offset?: number;
|
|
34
|
+
distinct?: boolean;
|
|
35
|
+
orderBy?: {
|
|
36
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
37
|
+
direction: import("../../types/base.js").OrderDirection;
|
|
38
|
+
}[] | undefined;
|
|
39
|
+
joins?: import("../../types/base.js").JoinClause[];
|
|
40
|
+
ctes?: string[];
|
|
41
|
+
unionQueries?: string[];
|
|
42
|
+
settings?: string;
|
|
43
|
+
};
|
|
44
|
+
startWhereGroup(): {
|
|
45
|
+
where: import("../../types/base.js").WhereCondition[];
|
|
46
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
47
|
+
groupBy?: string[];
|
|
48
|
+
having?: string[];
|
|
49
|
+
limit?: number;
|
|
50
|
+
offset?: number;
|
|
51
|
+
distinct?: boolean;
|
|
52
|
+
orderBy?: {
|
|
53
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
54
|
+
direction: import("../../types/base.js").OrderDirection;
|
|
55
|
+
}[] | undefined;
|
|
56
|
+
joins?: import("../../types/base.js").JoinClause[];
|
|
57
|
+
parameters?: any[];
|
|
58
|
+
ctes?: string[];
|
|
59
|
+
unionQueries?: string[];
|
|
60
|
+
settings?: string;
|
|
61
|
+
};
|
|
62
|
+
startOrWhereGroup(): {
|
|
63
|
+
where: import("../../types/base.js").WhereCondition[];
|
|
64
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
65
|
+
groupBy?: string[];
|
|
66
|
+
having?: string[];
|
|
67
|
+
limit?: number;
|
|
68
|
+
offset?: number;
|
|
69
|
+
distinct?: boolean;
|
|
70
|
+
orderBy?: {
|
|
71
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
72
|
+
direction: import("../../types/base.js").OrderDirection;
|
|
73
|
+
}[] | undefined;
|
|
74
|
+
joins?: import("../../types/base.js").JoinClause[];
|
|
75
|
+
parameters?: any[];
|
|
76
|
+
ctes?: string[];
|
|
77
|
+
unionQueries?: string[];
|
|
78
|
+
settings?: string;
|
|
79
|
+
};
|
|
80
|
+
endWhereGroup(): {
|
|
81
|
+
where: import("../../types/base.js").WhereCondition[];
|
|
82
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
83
|
+
groupBy?: string[];
|
|
84
|
+
having?: string[];
|
|
85
|
+
limit?: number;
|
|
86
|
+
offset?: number;
|
|
87
|
+
distinct?: boolean;
|
|
88
|
+
orderBy?: {
|
|
89
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
90
|
+
direction: import("../../types/base.js").OrderDirection;
|
|
91
|
+
}[] | undefined;
|
|
92
|
+
joins?: import("../../types/base.js").JoinClause[];
|
|
93
|
+
parameters?: any[];
|
|
94
|
+
ctes?: string[];
|
|
95
|
+
unionQueries?: string[];
|
|
96
|
+
settings?: string;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=filtering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
export class FilteringFeature {
|
|
2
|
+
builder;
|
|
3
|
+
constructor(builder) {
|
|
4
|
+
this.builder = builder;
|
|
5
|
+
}
|
|
6
|
+
addCondition(conjunction, column, operator, value) {
|
|
7
|
+
const config = this.builder.getConfig();
|
|
8
|
+
const where = config.where || [];
|
|
9
|
+
const parameters = config.parameters || [];
|
|
10
|
+
const columnString = Array.isArray(column)
|
|
11
|
+
? `(${column.map(String).join(', ')})`
|
|
12
|
+
: String(column);
|
|
13
|
+
where.push({
|
|
14
|
+
column: columnString,
|
|
15
|
+
operator,
|
|
16
|
+
value,
|
|
17
|
+
conjunction,
|
|
18
|
+
type: 'condition'
|
|
19
|
+
});
|
|
20
|
+
if (operator === 'in' || operator === 'notIn' || operator === 'globalIn' || operator === 'globalNotIn') {
|
|
21
|
+
if (!Array.isArray(value)) {
|
|
22
|
+
throw new Error(`Expected an array for ${operator} operator, but got ${typeof value}`);
|
|
23
|
+
}
|
|
24
|
+
parameters.push(...value);
|
|
25
|
+
}
|
|
26
|
+
else if (operator === 'inTuple' || operator === 'globalInTuple') {
|
|
27
|
+
if (!Array.isArray(value)) {
|
|
28
|
+
throw new Error(`Expected an array of tuples for ${operator} operator, but got ${typeof value}`);
|
|
29
|
+
}
|
|
30
|
+
value.forEach((tuple) => {
|
|
31
|
+
parameters.push(...tuple);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else if (operator === 'inSubquery' || operator === 'globalInSubquery') {
|
|
35
|
+
if (typeof value !== 'string') {
|
|
36
|
+
throw new Error(`Expected a string (subquery) for ${operator} operator, but got ${typeof value}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (operator === 'inTable' || operator === 'globalInTable') {
|
|
40
|
+
if (typeof value !== 'string') {
|
|
41
|
+
throw new Error(`Expected a string (table name) for ${operator} operator, but got ${typeof value}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (operator === 'between') {
|
|
45
|
+
parameters.push(value[0], value[1]);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
parameters.push(value);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
...config,
|
|
52
|
+
where,
|
|
53
|
+
parameters
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
addExpressionCondition(conjunction, expression) {
|
|
57
|
+
const config = this.builder.getConfig();
|
|
58
|
+
const where = config.where || [];
|
|
59
|
+
const parameters = config.parameters || [];
|
|
60
|
+
where.push({
|
|
61
|
+
type: 'expression',
|
|
62
|
+
expression: expression.sql,
|
|
63
|
+
parameters: expression.parameters,
|
|
64
|
+
conjunction
|
|
65
|
+
});
|
|
66
|
+
parameters.push(...expression.parameters);
|
|
67
|
+
return {
|
|
68
|
+
...config,
|
|
69
|
+
where,
|
|
70
|
+
parameters
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
startWhereGroup() {
|
|
74
|
+
const config = this.builder.getConfig();
|
|
75
|
+
const where = config.where || [];
|
|
76
|
+
where.push({
|
|
77
|
+
column: '',
|
|
78
|
+
operator: 'eq',
|
|
79
|
+
value: null,
|
|
80
|
+
conjunction: 'AND',
|
|
81
|
+
type: 'group-start'
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
...config,
|
|
85
|
+
where
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
startOrWhereGroup() {
|
|
89
|
+
const config = this.builder.getConfig();
|
|
90
|
+
const where = config.where || [];
|
|
91
|
+
where.push({
|
|
92
|
+
column: '',
|
|
93
|
+
operator: 'eq',
|
|
94
|
+
value: null,
|
|
95
|
+
conjunction: 'OR',
|
|
96
|
+
type: 'group-start'
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
...config,
|
|
100
|
+
where
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
endWhereGroup() {
|
|
104
|
+
const config = this.builder.getConfig();
|
|
105
|
+
const where = config.where || [];
|
|
106
|
+
where.push({
|
|
107
|
+
column: '',
|
|
108
|
+
operator: 'eq',
|
|
109
|
+
value: null,
|
|
110
|
+
conjunction: 'AND',
|
|
111
|
+
type: 'group-end'
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
...config,
|
|
115
|
+
where
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BuilderState, SchemaDefinition } from '../types/builder-state.js';
|
|
2
|
+
import { QueryBuilder } from '../query-builder.js';
|
|
3
|
+
import { JoinType } from '../../types/index.js';
|
|
4
|
+
export declare class JoinFeature<Schema extends SchemaDefinition<Schema>, State extends BuilderState<Schema, string, any, keyof Schema, Partial<Record<string, keyof Schema>>>> {
|
|
5
|
+
private builder;
|
|
6
|
+
constructor(builder: QueryBuilder<Schema, State>);
|
|
7
|
+
addJoin<TableName extends keyof Schema>(type: JoinType, table: TableName, leftColumn: string, rightColumn: `${TableName & string}.${keyof Schema[TableName] & string}`, alias?: string): {
|
|
8
|
+
joins: import("../../types/base.js").JoinClause[];
|
|
9
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
10
|
+
where?: import("../../types/base.js").WhereCondition[];
|
|
11
|
+
groupBy?: string[];
|
|
12
|
+
having?: string[];
|
|
13
|
+
limit?: number;
|
|
14
|
+
offset?: number;
|
|
15
|
+
distinct?: boolean;
|
|
16
|
+
orderBy?: {
|
|
17
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
18
|
+
direction: import("../../types/base.js").OrderDirection;
|
|
19
|
+
}[] | undefined;
|
|
20
|
+
parameters?: any[];
|
|
21
|
+
ctes?: string[];
|
|
22
|
+
unionQueries?: string[];
|
|
23
|
+
settings?: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=joins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"joins.d.ts","sourceRoot":"","sources":["../../../src/core/features/joins.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,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,qBAAa,WAAW,CACtB,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,SAAS,SAAS,MAAM,MAAM,EACpC,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,SAAS,EAChB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,GAAG,SAAS,GAAG,MAAM,IAAI,MAAM,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,EAAE,EACxE,KAAK,CAAC,EAAE,MAAM;;;;;;;;;;;;;;;;;;CAYjB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class JoinFeature {
|
|
2
|
+
builder;
|
|
3
|
+
constructor(builder) {
|
|
4
|
+
this.builder = builder;
|
|
5
|
+
}
|
|
6
|
+
addJoin(type, table, leftColumn, rightColumn, alias) {
|
|
7
|
+
const config = this.builder.getConfig();
|
|
8
|
+
const newConfig = {
|
|
9
|
+
...config,
|
|
10
|
+
joins: [
|
|
11
|
+
...(config.joins || []),
|
|
12
|
+
{ type, table: String(table), leftColumn: String(leftColumn), rightColumn, alias }
|
|
13
|
+
]
|
|
14
|
+
};
|
|
15
|
+
return newConfig;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { BuilderState, SchemaDefinition } from '../types/builder-state.js';
|
|
2
|
+
import { QueryBuilder } from '../query-builder.js';
|
|
3
|
+
import { OrderDirection } from '../../types/index.js';
|
|
4
|
+
export declare class QueryModifiersFeature<Schema extends SchemaDefinition<Schema>, State extends BuilderState<Schema, string, any, keyof Schema, Partial<Record<string, keyof Schema>>>> {
|
|
5
|
+
private builder;
|
|
6
|
+
constructor(builder: QueryBuilder<Schema, State>);
|
|
7
|
+
addGroupBy(columns: string | string[]): {
|
|
8
|
+
groupBy: string[];
|
|
9
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
10
|
+
where?: import("../../types/base.js").WhereCondition[];
|
|
11
|
+
having?: string[];
|
|
12
|
+
limit?: number;
|
|
13
|
+
offset?: number;
|
|
14
|
+
distinct?: boolean;
|
|
15
|
+
orderBy?: {
|
|
16
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
17
|
+
direction: OrderDirection;
|
|
18
|
+
}[] | undefined;
|
|
19
|
+
joins?: import("../../types/base.js").JoinClause[];
|
|
20
|
+
parameters?: any[];
|
|
21
|
+
ctes?: string[];
|
|
22
|
+
unionQueries?: string[];
|
|
23
|
+
settings?: string;
|
|
24
|
+
};
|
|
25
|
+
addLimit(count: number): {
|
|
26
|
+
limit: number;
|
|
27
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
28
|
+
where?: import("../../types/base.js").WhereCondition[];
|
|
29
|
+
groupBy?: string[];
|
|
30
|
+
having?: string[];
|
|
31
|
+
offset?: number;
|
|
32
|
+
distinct?: boolean;
|
|
33
|
+
orderBy?: {
|
|
34
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
35
|
+
direction: OrderDirection;
|
|
36
|
+
}[] | undefined;
|
|
37
|
+
joins?: import("../../types/base.js").JoinClause[];
|
|
38
|
+
parameters?: any[];
|
|
39
|
+
ctes?: string[];
|
|
40
|
+
unionQueries?: string[];
|
|
41
|
+
settings?: string;
|
|
42
|
+
};
|
|
43
|
+
addOffset(count: number): {
|
|
44
|
+
offset: number;
|
|
45
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
46
|
+
where?: import("../../types/base.js").WhereCondition[];
|
|
47
|
+
groupBy?: string[];
|
|
48
|
+
having?: string[];
|
|
49
|
+
limit?: number;
|
|
50
|
+
distinct?: boolean;
|
|
51
|
+
orderBy?: {
|
|
52
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
53
|
+
direction: OrderDirection;
|
|
54
|
+
}[] | undefined;
|
|
55
|
+
joins?: import("../../types/base.js").JoinClause[];
|
|
56
|
+
parameters?: any[];
|
|
57
|
+
ctes?: string[];
|
|
58
|
+
unionQueries?: string[];
|
|
59
|
+
settings?: string;
|
|
60
|
+
};
|
|
61
|
+
addOrderBy(column: string, direction?: OrderDirection): {
|
|
62
|
+
orderBy: {
|
|
63
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
64
|
+
direction: OrderDirection;
|
|
65
|
+
}[];
|
|
66
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
67
|
+
where?: import("../../types/base.js").WhereCondition[];
|
|
68
|
+
groupBy?: string[];
|
|
69
|
+
having?: string[];
|
|
70
|
+
limit?: number;
|
|
71
|
+
offset?: number;
|
|
72
|
+
distinct?: boolean;
|
|
73
|
+
joins?: import("../../types/base.js").JoinClause[];
|
|
74
|
+
parameters?: any[];
|
|
75
|
+
ctes?: string[];
|
|
76
|
+
unionQueries?: string[];
|
|
77
|
+
settings?: string;
|
|
78
|
+
};
|
|
79
|
+
addHaving(condition: string, parameters?: any[]): {
|
|
80
|
+
having: string[];
|
|
81
|
+
parameters: any[] | undefined;
|
|
82
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
83
|
+
where?: import("../../types/base.js").WhereCondition[];
|
|
84
|
+
groupBy?: string[];
|
|
85
|
+
limit?: number;
|
|
86
|
+
offset?: number;
|
|
87
|
+
distinct?: boolean;
|
|
88
|
+
orderBy?: {
|
|
89
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
90
|
+
direction: OrderDirection;
|
|
91
|
+
}[] | undefined;
|
|
92
|
+
joins?: import("../../types/base.js").JoinClause[];
|
|
93
|
+
ctes?: string[];
|
|
94
|
+
unionQueries?: string[];
|
|
95
|
+
settings?: string;
|
|
96
|
+
};
|
|
97
|
+
setDistinct(): {
|
|
98
|
+
distinct: boolean;
|
|
99
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
100
|
+
where?: import("../../types/base.js").WhereCondition[];
|
|
101
|
+
groupBy?: string[];
|
|
102
|
+
having?: string[];
|
|
103
|
+
limit?: number;
|
|
104
|
+
offset?: number;
|
|
105
|
+
orderBy?: {
|
|
106
|
+
column: keyof State["output"] | import("../../types/schema.js").TableColumn<Schema>;
|
|
107
|
+
direction: OrderDirection;
|
|
108
|
+
}[] | undefined;
|
|
109
|
+
joins?: import("../../types/base.js").JoinClause[];
|
|
110
|
+
parameters?: any[];
|
|
111
|
+
ctes?: string[];
|
|
112
|
+
unionQueries?: string[];
|
|
113
|
+
settings?: string;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=query-modifiers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-modifiers.d.ts","sourceRoot":"","sources":["../../../src/core/features/query-modifiers.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;AAEtD,qBAAa,qBAAqB,CAChC,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,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;;;;;;;;;;;;;;;;;;IAQrC,QAAQ,CAAC,KAAK,EAAE,MAAM;;;;;;;;;;;;;;;;;;IAQtB,SAAS,CAAC,KAAK,EAAE,MAAM;;;;;;;;;;;;;;;;;;IAQvB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,cAAsB;;;;;;;;;;;;;;;;;;IAQ5D,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE;;;;;;;;;;;;;;;;;;IAY/C,WAAW;;;;;;;;;;;;;;;;;;CAOZ"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export class QueryModifiersFeature {
|
|
2
|
+
builder;
|
|
3
|
+
constructor(builder) {
|
|
4
|
+
this.builder = builder;
|
|
5
|
+
}
|
|
6
|
+
addGroupBy(columns) {
|
|
7
|
+
const config = this.builder.getConfig();
|
|
8
|
+
return {
|
|
9
|
+
...config,
|
|
10
|
+
groupBy: Array.isArray(columns) ? columns.map(String) : [String(columns)]
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
addLimit(count) {
|
|
14
|
+
const config = this.builder.getConfig();
|
|
15
|
+
return {
|
|
16
|
+
...config,
|
|
17
|
+
limit: count
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
addOffset(count) {
|
|
21
|
+
const config = this.builder.getConfig();
|
|
22
|
+
return {
|
|
23
|
+
...config,
|
|
24
|
+
offset: count
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
addOrderBy(column, direction = 'ASC') {
|
|
28
|
+
const config = this.builder.getConfig();
|
|
29
|
+
return {
|
|
30
|
+
...config,
|
|
31
|
+
orderBy: [...(config.orderBy || []), { column, direction }]
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
addHaving(condition, parameters) {
|
|
35
|
+
const config = this.builder.getConfig();
|
|
36
|
+
const having = [...(config.having || []), condition];
|
|
37
|
+
const newParams = parameters ? [...(config.parameters || []), ...parameters] : config.parameters;
|
|
38
|
+
return {
|
|
39
|
+
...config,
|
|
40
|
+
having,
|
|
41
|
+
parameters: newParams
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
setDistinct() {
|
|
45
|
+
const config = this.builder.getConfig();
|
|
46
|
+
return {
|
|
47
|
+
...config,
|
|
48
|
+
distinct: true
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { QueryConfig } from '../../types/index.js';
|
|
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
|
|
@@ -0,0 +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,sBAAsB,CAAC;AAEnE,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;IAoGlD,OAAO,CAAC,cAAc;IActB,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,MAAM;CAUnD"}
|