@hypequery/clickhouse 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-CLI.md +123 -0
- package/README.md +276 -0
- package/dist/cli/bin.js +151 -0
- package/dist/cli/generate-types.d.ts +5 -0
- package/dist/cli/generate-types.js +91 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +2 -0
- package/dist/core/connection.d.ts.map +1 -0
- package/dist/core/connection.js +34 -0
- package/dist/core/cross-filter.d.ts.map +1 -0
- package/dist/core/cross-filter.js +218 -0
- package/dist/core/features/aggregations.d.ts.map +1 -0
- package/dist/core/features/aggregations.js +35 -0
- package/dist/core/features/analytics.d.ts.map +1 -0
- package/dist/core/features/analytics.js +35 -0
- package/dist/core/features/executor.d.ts.map +1 -0
- package/dist/core/features/executor.js +136 -0
- package/dist/core/features/filtering.d.ts.map +1 -0
- package/dist/core/features/filtering.js +30 -0
- package/dist/core/features/joins.d.ts.map +1 -0
- package/dist/core/features/joins.js +16 -0
- package/dist/core/features/pagination.d.ts.map +1 -0
- package/dist/core/features/pagination.js +190 -0
- package/dist/core/features/query-modifiers.d.ts.map +1 -0
- package/dist/core/features/query-modifiers.js +50 -0
- package/dist/core/formatters/sql-formatter.d.ts.map +1 -0
- package/dist/core/formatters/sql-formatter.js +69 -0
- package/dist/core/join-relationships.d.ts.map +1 -0
- package/dist/core/join-relationships.js +56 -0
- package/dist/core/query-builder.d.ts.map +1 -0
- package/dist/core/query-builder.js +372 -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.map +1 -0
- package/dist/core/tests/integration/setup.js +274 -0
- package/dist/core/tests/test-utils.d.ts.map +1 -0
- package/dist/core/tests/test-utils.js +32 -0
- package/dist/core/utils/logger.d.ts.map +1 -0
- package/dist/core/utils/logger.js +98 -0
- package/dist/core/utils/sql-expressions.d.ts.map +1 -0
- package/dist/core/utils/sql-expressions.js +73 -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.map +1 -0
- package/dist/core/validators/filter-validator.js +19 -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.map +1 -0
- package/dist/formatters/index.js +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/types/base.d.ts.map +1 -0
- package/dist/types/base.js +1 -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.map +1 -0
- package/dist/types/filters.js +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/package.json +67 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
export class PaginationFeature {
|
|
2
|
+
constructor(builder) {
|
|
3
|
+
this.builder = builder;
|
|
4
|
+
// Create a unique key for this pagination instance based on the table and sort
|
|
5
|
+
this.stackKey = builder.getTableName();
|
|
6
|
+
if (!PaginationFeature.cursorStacks.has(this.stackKey)) {
|
|
7
|
+
PaginationFeature.cursorStacks.set(this.stackKey, { stack: [], position: -1 });
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
get cursorStack() {
|
|
11
|
+
return PaginationFeature.cursorStacks.get(this.stackKey).stack;
|
|
12
|
+
}
|
|
13
|
+
set cursorStack(value) {
|
|
14
|
+
const current = PaginationFeature.cursorStacks.get(this.stackKey);
|
|
15
|
+
PaginationFeature.cursorStacks.set(this.stackKey, { ...current, stack: value });
|
|
16
|
+
}
|
|
17
|
+
get currentPosition() {
|
|
18
|
+
return PaginationFeature.cursorStacks.get(this.stackKey).position;
|
|
19
|
+
}
|
|
20
|
+
set currentPosition(value) {
|
|
21
|
+
const current = PaginationFeature.cursorStacks.get(this.stackKey);
|
|
22
|
+
PaginationFeature.cursorStacks.set(this.stackKey, { ...current, position: value });
|
|
23
|
+
}
|
|
24
|
+
encodeCursor(values) {
|
|
25
|
+
return Buffer.from(JSON.stringify(values)).toString('base64');
|
|
26
|
+
}
|
|
27
|
+
decodeCursor(cursor) {
|
|
28
|
+
return JSON.parse(Buffer.from(cursor, 'base64').toString());
|
|
29
|
+
}
|
|
30
|
+
async paginate(options) {
|
|
31
|
+
const { pageSize, after, before, orderBy = [] } = options;
|
|
32
|
+
const requestSize = pageSize + 1;
|
|
33
|
+
// Update cursor stack
|
|
34
|
+
if (after) {
|
|
35
|
+
// Moving forward: add new cursor and update position
|
|
36
|
+
if (this.currentPosition < this.cursorStack.length - 1) {
|
|
37
|
+
// If we're not at the end, truncate the stack
|
|
38
|
+
this.cursorStack = this.cursorStack.slice(0, this.currentPosition + 1);
|
|
39
|
+
}
|
|
40
|
+
this.cursorStack = [...this.cursorStack, after];
|
|
41
|
+
this.currentPosition = this.cursorStack.length - 1;
|
|
42
|
+
}
|
|
43
|
+
else if (before) {
|
|
44
|
+
// Moving backward: find the cursor in the stack
|
|
45
|
+
const cursorIndex = this.cursorStack.indexOf(before);
|
|
46
|
+
if (cursorIndex === -1) {
|
|
47
|
+
// If cursor not found in stack, add it
|
|
48
|
+
if (this.currentPosition === this.cursorStack.length - 1) {
|
|
49
|
+
this.cursorStack = [...this.cursorStack, before];
|
|
50
|
+
}
|
|
51
|
+
// Move back one position
|
|
52
|
+
this.currentPosition = Math.max(-1, this.currentPosition - 1);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// Move to the previous cursor position
|
|
56
|
+
this.currentPosition = Math.max(-1, cursorIndex - 1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// Reset for first page only if we don't have a cursor
|
|
61
|
+
if (!this.cursorStack.length) {
|
|
62
|
+
this.cursorStack = [];
|
|
63
|
+
this.currentPosition = -1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Apply ordering first
|
|
67
|
+
orderBy.forEach(({ column, direction }) => {
|
|
68
|
+
this.builder.orderBy(column, direction);
|
|
69
|
+
});
|
|
70
|
+
// Handle cursor-based pagination
|
|
71
|
+
const cursor = after || before;
|
|
72
|
+
if (cursor && orderBy && orderBy.length > 0) {
|
|
73
|
+
const [{ column, direction }] = orderBy;
|
|
74
|
+
const columnName = String(column);
|
|
75
|
+
const cursorValues = this.decodeCursor(cursor);
|
|
76
|
+
const value = cursorValues[columnName];
|
|
77
|
+
if (before) {
|
|
78
|
+
// For backward pagination:
|
|
79
|
+
// If sorting DESC, we want records > cursor
|
|
80
|
+
// If sorting ASC, we want records < cursor
|
|
81
|
+
const operator = direction === 'DESC' ? 'gt' : 'lt';
|
|
82
|
+
this.builder.where(columnName, operator, value);
|
|
83
|
+
// Reverse the order for backward pagination
|
|
84
|
+
orderBy.forEach(({ column, direction }) => {
|
|
85
|
+
const reversedDirection = direction === 'DESC' ? 'ASC' : 'DESC';
|
|
86
|
+
this.builder.orderBy(column, reversedDirection);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// For forward pagination:
|
|
91
|
+
// If sorting DESC, we want records < cursor
|
|
92
|
+
// If sorting ASC, we want records > cursor
|
|
93
|
+
const operator = direction === 'DESC' ? 'lt' : 'gt';
|
|
94
|
+
this.builder.where(columnName, operator, value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
this.builder.limit(requestSize);
|
|
98
|
+
// Execute query
|
|
99
|
+
let results = await this.builder.execute();
|
|
100
|
+
// For backward pagination, we need to reverse the results
|
|
101
|
+
if (before) {
|
|
102
|
+
results = results.reverse();
|
|
103
|
+
}
|
|
104
|
+
// Only take pageSize records for the actual data
|
|
105
|
+
const data = results.slice(0, pageSize);
|
|
106
|
+
// Generate cursors
|
|
107
|
+
const startCursor = data.length > 0 ? this.generateCursor(data[0], orderBy) : '';
|
|
108
|
+
const endCursor = data.length > 0 ? this.generateCursor(data[data.length - 1], orderBy) : '';
|
|
109
|
+
// Determine if there are more pages
|
|
110
|
+
const hasMore = results.length > pageSize;
|
|
111
|
+
// For the first page
|
|
112
|
+
if (!cursor) {
|
|
113
|
+
return {
|
|
114
|
+
data,
|
|
115
|
+
pageInfo: {
|
|
116
|
+
hasNextPage: hasMore,
|
|
117
|
+
hasPreviousPage: data.length > 0 && this.currentPosition > 0, // Only true if we have results AND previous cursors
|
|
118
|
+
startCursor,
|
|
119
|
+
endCursor,
|
|
120
|
+
totalCount: 0,
|
|
121
|
+
totalPages: 0,
|
|
122
|
+
pageSize
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
// For pages accessed via 'before' cursor
|
|
127
|
+
if (before) {
|
|
128
|
+
return {
|
|
129
|
+
data,
|
|
130
|
+
pageInfo: {
|
|
131
|
+
hasNextPage: true, // We can always go forward when we've gone back
|
|
132
|
+
hasPreviousPage: data.length > 0 && (this.currentPosition >= 0 || hasMore), // Need results to have previous page
|
|
133
|
+
startCursor,
|
|
134
|
+
endCursor,
|
|
135
|
+
totalCount: 0,
|
|
136
|
+
totalPages: 0,
|
|
137
|
+
pageSize
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
// For pages accessed via 'after' cursor
|
|
142
|
+
return {
|
|
143
|
+
data,
|
|
144
|
+
pageInfo: {
|
|
145
|
+
hasNextPage: hasMore, // Can go forward if we have more results
|
|
146
|
+
hasPreviousPage: data.length > 0, // Need results to have previous page
|
|
147
|
+
startCursor,
|
|
148
|
+
endCursor,
|
|
149
|
+
totalCount: 0,
|
|
150
|
+
totalPages: 0,
|
|
151
|
+
pageSize
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
generateCursor(record, orderBy) {
|
|
156
|
+
const cursorData = {};
|
|
157
|
+
if (orderBy) {
|
|
158
|
+
orderBy.forEach(({ column }) => {
|
|
159
|
+
const columnName = String(column);
|
|
160
|
+
cursorData[columnName] = record[columnName];
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// Use primary key or first column as default
|
|
165
|
+
const [firstColumn] = Object.keys(record);
|
|
166
|
+
if (firstColumn) {
|
|
167
|
+
cursorData[firstColumn] = record[firstColumn];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return this.encodeCursor(cursorData);
|
|
171
|
+
}
|
|
172
|
+
async firstPage(pageSize) {
|
|
173
|
+
return this.paginate({ pageSize });
|
|
174
|
+
}
|
|
175
|
+
async *iteratePages(pageSize) {
|
|
176
|
+
let currentCursor;
|
|
177
|
+
while (true) {
|
|
178
|
+
const result = await this.paginate({
|
|
179
|
+
pageSize,
|
|
180
|
+
after: currentCursor
|
|
181
|
+
});
|
|
182
|
+
yield result;
|
|
183
|
+
if (!result.pageInfo.hasNextPage) {
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
currentCursor = result.pageInfo.endCursor;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
PaginationFeature.cursorStacks = new Map();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-modifiers.d.ts","sourceRoot":"","sources":["../../../src/core/features/query-modifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEtE,qBAAa,qBAAqB,CAChC,MAAM,SAAS;IAAE,CAAC,SAAS,EAAE,MAAM,GAAG;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAAA;KAAE,CAAA;CAAE,EAC5E,CAAC,EACD,SAAS,SAAS,OAAO,GAAG,KAAK,EACjC,YAAY,GAAG,EAAE,EACjB,SAAS,GAAG,CAAC;IAED,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,CAAC;IAExF,UAAU,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;;;;;;IAQ1F,QAAQ,CAAC,KAAK,EAAE,MAAM;;;;;;;;;;;;;;;;;;IAQtB,SAAS,CAAC,KAAK,EAAE,MAAM;;;;;;;;;;;;;;;;;;IAQvB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,GAAE,cAAsB;;;;;;;;;;;;;;;;;;IAQhG,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE;;;;;;;;;;;;;;;;;;IAY/C,WAAW;;;;;;;;;;;;;;;;;;CAOZ"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export class QueryModifiersFeature {
|
|
2
|
+
constructor(builder) {
|
|
3
|
+
this.builder = builder;
|
|
4
|
+
}
|
|
5
|
+
addGroupBy(columns) {
|
|
6
|
+
const config = this.builder.getConfig();
|
|
7
|
+
return {
|
|
8
|
+
...config,
|
|
9
|
+
groupBy: Array.isArray(columns) ? columns.map(String) : [String(columns)]
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
addLimit(count) {
|
|
13
|
+
const config = this.builder.getConfig();
|
|
14
|
+
return {
|
|
15
|
+
...config,
|
|
16
|
+
limit: count
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
addOffset(count) {
|
|
20
|
+
const config = this.builder.getConfig();
|
|
21
|
+
return {
|
|
22
|
+
...config,
|
|
23
|
+
offset: count
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
addOrderBy(column, direction = 'ASC') {
|
|
27
|
+
const config = this.builder.getConfig();
|
|
28
|
+
return {
|
|
29
|
+
...config,
|
|
30
|
+
orderBy: [...(config.orderBy || []), { column, direction }]
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
addHaving(condition, parameters) {
|
|
34
|
+
const config = this.builder.getConfig();
|
|
35
|
+
const having = [...(config.having || []), condition];
|
|
36
|
+
const newParams = parameters ? [...(config.parameters || []), ...parameters] : config.parameters;
|
|
37
|
+
return {
|
|
38
|
+
...config,
|
|
39
|
+
having,
|
|
40
|
+
parameters: newParams
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
setDistinct() {
|
|
44
|
+
const config = this.builder.getConfig();
|
|
45
|
+
return {
|
|
46
|
+
...config,
|
|
47
|
+
distinct: true
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -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,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;IA4BlD,OAAO,CAAC,cAAc;IActB,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,MAAM;CAUnD"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export class SQLFormatter {
|
|
2
|
+
formatSelect(config) {
|
|
3
|
+
const distinctClause = config.distinct ? 'DISTINCT ' : '';
|
|
4
|
+
if (!config.select?.length)
|
|
5
|
+
return distinctClause + '*';
|
|
6
|
+
return distinctClause + config.select.join(', ');
|
|
7
|
+
}
|
|
8
|
+
formatGroupBy(config) {
|
|
9
|
+
const groupBy = config.groupBy;
|
|
10
|
+
if (!groupBy?.length)
|
|
11
|
+
return '';
|
|
12
|
+
if (Array.isArray(groupBy)) {
|
|
13
|
+
return groupBy.join(', ');
|
|
14
|
+
}
|
|
15
|
+
return String(groupBy);
|
|
16
|
+
}
|
|
17
|
+
formatWhere(config) {
|
|
18
|
+
if (!config.where?.length)
|
|
19
|
+
return '';
|
|
20
|
+
return config.where
|
|
21
|
+
.map((condition, index) => {
|
|
22
|
+
const { column, operator, value, conjunction } = condition;
|
|
23
|
+
const prefix = index === 0 ? '' : ` ${conjunction} `;
|
|
24
|
+
if (operator === 'in' || operator === 'notIn') {
|
|
25
|
+
if (!Array.isArray(value)) {
|
|
26
|
+
throw new Error(`Expected an array for ${operator} operator, but got ${typeof value}`);
|
|
27
|
+
}
|
|
28
|
+
if (value.length === 0) {
|
|
29
|
+
return `${prefix}1 = 0`;
|
|
30
|
+
}
|
|
31
|
+
const placeholders = value.map(() => '?').join(', ');
|
|
32
|
+
return `${prefix}${column} ${operator === 'in' ? 'IN' : 'NOT IN'} (${placeholders})`.trim();
|
|
33
|
+
}
|
|
34
|
+
else if (operator === 'between') {
|
|
35
|
+
return `${prefix}${column} BETWEEN ? AND ?`.trim();
|
|
36
|
+
}
|
|
37
|
+
else if (operator === 'like') {
|
|
38
|
+
return `${prefix}${column} LIKE ?`.trim();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return `${prefix}${column} ${this.getSqlOperator(operator)} ?`.trim();
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
.join(' ');
|
|
45
|
+
}
|
|
46
|
+
getSqlOperator(operator) {
|
|
47
|
+
switch (operator) {
|
|
48
|
+
case 'eq': return '=';
|
|
49
|
+
case 'neq': return '!=';
|
|
50
|
+
case 'gt': return '>';
|
|
51
|
+
case 'gte': return '>=';
|
|
52
|
+
case 'lt': return '<';
|
|
53
|
+
case 'lte': return '<=';
|
|
54
|
+
case 'like': return 'LIKE';
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(`Unsupported operator: ${operator}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
formatJoins(config) {
|
|
60
|
+
if (!config.joins?.length)
|
|
61
|
+
return '';
|
|
62
|
+
return config.joins.map(join => {
|
|
63
|
+
const tableClause = join.alias
|
|
64
|
+
? `${join.table} AS ${join.alias}`
|
|
65
|
+
: join.table;
|
|
66
|
+
return `${join.type} JOIN ${tableClause} ON ${join.leftColumn} = ${join.rightColumn}`;
|
|
67
|
+
}).join(' ');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"join-relationships.d.ts","sourceRoot":"","sources":["../../src/core/join-relationships.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEhD,MAAM,WAAW,QAAQ,CAAC,MAAM;IAC9B,IAAI,EAAE,MAAM,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED,qBAAa,iBAAiB,CAAC,MAAM,SAAS;IAAE,CAAC,SAAS,EAAE,MAAM,GAAG;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAAA;KAAE,CAAA;CAAE;IACzG,OAAO,CAAC,KAAK,CAA4D;IAEzE;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI;IAOlD;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI;IAU1D;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,EAAE,GAAG,SAAS;IAIpE;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI7B;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,uBAAuB,IAAI,MAAM,EAAE;CAGpC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export class JoinRelationships {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.paths = new Map();
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Define a single join relationship
|
|
7
|
+
*/
|
|
8
|
+
define(name, path) {
|
|
9
|
+
if (this.paths.has(name)) {
|
|
10
|
+
throw new Error(`Join relationship '${name}' is already defined`);
|
|
11
|
+
}
|
|
12
|
+
this.paths.set(name, path);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Define a chain of join relationships
|
|
16
|
+
*/
|
|
17
|
+
defineChain(name, paths) {
|
|
18
|
+
if (this.paths.has(name)) {
|
|
19
|
+
throw new Error(`Join chain '${name}' is already defined`);
|
|
20
|
+
}
|
|
21
|
+
if (paths.length === 0) {
|
|
22
|
+
throw new Error('Join chain must contain at least one path');
|
|
23
|
+
}
|
|
24
|
+
this.paths.set(name, paths);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get a join relationship by name
|
|
28
|
+
*/
|
|
29
|
+
get(name) {
|
|
30
|
+
return this.paths.get(name);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if a join relationship exists
|
|
34
|
+
*/
|
|
35
|
+
has(name) {
|
|
36
|
+
return this.paths.has(name);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Remove a join relationship
|
|
40
|
+
*/
|
|
41
|
+
remove(name) {
|
|
42
|
+
return this.paths.delete(name);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Clear all join relationships
|
|
46
|
+
*/
|
|
47
|
+
clear() {
|
|
48
|
+
this.paths.clear();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get all defined relationship names
|
|
52
|
+
*/
|
|
53
|
+
getDefinedRelationships() {
|
|
54
|
+
return Array.from(this.paths.keys());
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +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,EAEhB,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,EAAE,MAAM,yBAAyB,CAAC;AAExD;;;;;;GAMG;AACH,qBAAa,YAAY,CACvB,MAAM,SAAS;IAAE,CAAC,SAAS,EAAE,MAAM,GAAG;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAAA;KAAE,CAAA;CAAE,EAC5E,CAAC,EACD,SAAS,SAAS,OAAO,GAAG,KAAK,EACjC,YAAY,GAAG,EAAE,EACjB,SAAS,GAAG,CAAC;IAEb,OAAO,C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