@iamkirbki/database-handler-core 4.3.1 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/abstract/Controller.d.ts +17 -0
  2. package/dist/abstract/Controller.d.ts.map +1 -0
  3. package/dist/abstract/Controller.js +47 -0
  4. package/dist/abstract/Model.d.ts +33 -19
  5. package/dist/abstract/Model.d.ts.map +1 -1
  6. package/dist/abstract/Model.js +177 -119
  7. package/dist/abstract/SchemaTableBuilder.d.ts +1 -1
  8. package/dist/abstract/SchemaTableBuilder.d.ts.map +1 -1
  9. package/dist/abstract/model/ModelRelation.d.ts +23 -0
  10. package/dist/abstract/model/ModelRelation.d.ts.map +1 -0
  11. package/dist/abstract/model/ModelRelation.js +130 -0
  12. package/dist/base/Query.d.ts +6 -4
  13. package/dist/base/Query.d.ts.map +1 -1
  14. package/dist/base/Query.js +62 -21
  15. package/dist/base/Record.d.ts.map +1 -1
  16. package/dist/base/Record.js +7 -5
  17. package/dist/base/Table.d.ts +5 -4
  18. package/dist/base/Table.d.ts.map +1 -1
  19. package/dist/base/Table.js +56 -31
  20. package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.d.ts +4 -0
  21. package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.d.ts.map +1 -0
  22. package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.js +6 -0
  23. package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.d.ts +4 -0
  24. package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.d.ts.map +1 -0
  25. package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.js +6 -0
  26. package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.d.ts +4 -0
  27. package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.d.ts.map +1 -0
  28. package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.js +6 -0
  29. package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.d.ts +4 -0
  30. package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.d.ts.map +1 -0
  31. package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.js +6 -0
  32. package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.d.ts +4 -0
  33. package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.d.ts.map +1 -0
  34. package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.js +6 -0
  35. package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.d.ts +4 -0
  36. package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.d.ts.map +1 -0
  37. package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.js +6 -0
  38. package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.d.ts +4 -0
  39. package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.d.ts.map +1 -0
  40. package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.js +6 -0
  41. package/dist/helpers/Errors/TableErrors/UnknownTableError.d.ts +4 -0
  42. package/dist/helpers/Errors/TableErrors/UnknownTableError.d.ts.map +1 -0
  43. package/dist/helpers/Errors/TableErrors/UnknownTableError.js +6 -0
  44. package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseDeleteQueryBuilder.d.ts +1 -0
  45. package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseDeleteQueryBuilder.d.ts.map +1 -0
  46. package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseDeleteQueryBuilder.js +1 -0
  47. package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseInsertQueryBuilder.d.ts +1 -0
  48. package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseInsertQueryBuilder.d.ts.map +1 -0
  49. package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseInsertQueryBuilder.js +11 -0
  50. package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.d.ts +11 -0
  51. package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.d.ts.map +1 -0
  52. package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.js +27 -0
  53. package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseUpdateQueryBuilder.d.ts +1 -0
  54. package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseUpdateQueryBuilder.d.ts.map +1 -0
  55. package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseUpdateQueryBuilder.js +1 -0
  56. package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.d.ts +9 -0
  57. package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.d.ts.map +1 -0
  58. package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.js +102 -0
  59. package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.d.ts +8 -0
  60. package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.d.ts.map +1 -0
  61. package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.js +63 -0
  62. package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.d.ts +8 -0
  63. package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.d.ts.map +1 -0
  64. package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.js +49 -0
  65. package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.d.ts +19 -0
  66. package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.d.ts.map +1 -0
  67. package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.js +60 -0
  68. package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.d.ts +9 -0
  69. package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.d.ts.map +1 -0
  70. package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.js +27 -0
  71. package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.d.ts +15 -0
  72. package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.d.ts.map +1 -0
  73. package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.js +74 -0
  74. package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.d.ts +10 -0
  75. package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.d.ts.map +1 -0
  76. package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.js +29 -0
  77. package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.d.ts +9 -0
  78. package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.d.ts.map +1 -0
  79. package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.js +27 -0
  80. package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.d.ts +8 -0
  81. package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.d.ts.map +1 -0
  82. package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.js +5 -0
  83. package/dist/helpers/QueryBuilders/QueryDecorators/ValuesDecorator.d.ts +1 -0
  84. package/dist/helpers/QueryBuilders/QueryDecorators/ValuesDecorator.d.ts.map +1 -0
  85. package/dist/helpers/QueryBuilders/QueryDecorators/ValuesDecorator.js +17 -0
  86. package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.d.ts +9 -0
  87. package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.d.ts.map +1 -0
  88. package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.js +29 -0
  89. package/dist/helpers/QueryBuilders/QueryExpressionBuilder.d.ts +54 -0
  90. package/dist/helpers/QueryBuilders/QueryExpressionBuilder.d.ts.map +1 -0
  91. package/dist/helpers/QueryBuilders/QueryExpressionBuilder.js +102 -0
  92. package/dist/helpers/QueryBuilders/QueryStatementBuilder.d.ts +16 -0
  93. package/dist/helpers/QueryBuilders/QueryStatementBuilder.d.ts.map +1 -0
  94. package/dist/helpers/QueryBuilders/QueryStatementBuilder.js +169 -0
  95. package/dist/helpers/QueryBuilders/SqlRenderer.d.ts +15 -0
  96. package/dist/helpers/QueryBuilders/SqlRenderer.d.ts.map +1 -0
  97. package/dist/helpers/QueryBuilders/SqlRenderer.js +79 -0
  98. package/dist/helpers/QueryBuilders/oldQueryStatementBuilder.d.ts +160 -0
  99. package/dist/helpers/QueryBuilders/oldQueryStatementBuilder.d.ts.map +1 -0
  100. package/dist/helpers/QueryBuilders/oldQueryStatementBuilder.js +217 -0
  101. package/dist/interfaces/IExpressionBuilder.d.ts +7 -0
  102. package/dist/interfaces/IExpressionBuilder.d.ts.map +1 -0
  103. package/dist/interfaces/IExpressionBuilder.js +1 -0
  104. package/dist/interfaces/IQueryBuilder.d.ts +5 -0
  105. package/dist/interfaces/IQueryBuilder.d.ts.map +1 -0
  106. package/dist/interfaces/IQueryBuilder.js +1 -0
  107. package/dist/runtime/Container.d.ts +1 -0
  108. package/dist/runtime/Container.d.ts.map +1 -1
  109. package/dist/runtime/Container.js +5 -2
  110. package/dist/runtime/QueryCache.d.ts +12 -0
  111. package/dist/runtime/QueryCache.d.ts.map +1 -0
  112. package/dist/runtime/QueryCache.js +26 -0
  113. package/dist/runtime/Repository.d.ts +6 -4
  114. package/dist/runtime/Repository.d.ts.map +1 -1
  115. package/dist/runtime/Repository.js +95 -60
  116. package/dist/types/expressions.d.ts +154 -0
  117. package/dist/types/expressions.d.ts.map +1 -0
  118. package/dist/types/expressions.js +6 -0
  119. package/dist/types/factories.d.ts +3 -2
  120. package/dist/types/factories.d.ts.map +1 -1
  121. package/dist/types/index.d.ts +1 -0
  122. package/dist/types/index.d.ts.map +1 -1
  123. package/dist/types/index.js +1 -0
  124. package/dist/types/model.d.ts +8 -8
  125. package/dist/types/model.d.ts.map +1 -1
  126. package/dist/types/query.d.ts +56 -2
  127. package/dist/types/query.d.ts.map +1 -1
  128. package/package.json +11 -3
  129. package/dist/helpers/QueryStatementBuilder.d.ts +0 -305
  130. package/dist/helpers/QueryStatementBuilder.d.ts.map +0 -1
  131. package/dist/helpers/QueryStatementBuilder.js +0 -416
@@ -1,416 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- /** Utility class for building SQL query strings */
11
- export default class QueryStatementBuilder {
12
- /**
13
- * Build a SELECT SQL statement with optional filtering, ordering, and pagination
14
- *
15
- * @param table - The table to select from
16
- * @param options - Query options including select columns, where conditions, orderBy, limit, offset
17
- * @returns Complete SELECT SQL statement string
18
- *
19
- * @example
20
- * ```typescript
21
- * // Select all columns
22
- * const query = QueryStatementBuilder.BuildSelect(usersTable);
23
- * // "SELECT * FROM users"
24
- *
25
- * // Select specific columns with filtering
26
- * const query = QueryStatementBuilder.BuildSelect(usersTable, {
27
- * select: 'id, name, email',
28
- * where: { status: 'active', age: 25 },
29
- * orderBy: 'created_at DESC',
30
- * limit: 10,
31
- * offset: 20
32
- * });
33
- * // "SELECT id, name, email FROM users WHERE status = @status AND age = @age ORDER BY created_at DESC LIMIT 10 OFFSET 20"
34
- * ```
35
- */
36
- static BuildSelect(tableName, options) {
37
- var _a;
38
- const queryParts = [];
39
- queryParts.push(`SELECT ${(_a = options === null || options === void 0 ? void 0 : options.select) !== null && _a !== void 0 ? _a : "*"}`);
40
- queryParts.push(`FROM "${tableName}"`);
41
- queryParts.push(this.BuildWhere(options === null || options === void 0 ? void 0 : options.where));
42
- queryParts.push(this.BuildQueryOptions(options !== null && options !== void 0 ? options : {}));
43
- return queryParts.join(" ");
44
- }
45
- /**
46
- * Build an INSERT SQL statement with named parameter placeholders
47
- *
48
- * @param table - The table to insert into
49
- * @param record - Object containing column names and their placeholder values
50
- * @returns Complete INSERT SQL statement string with @fieldName placeholders
51
- *
52
- * @example
53
- * ```typescript
54
- * const query = QueryStatementBuilder.BuildInsert(usersTable, {
55
- * name: 'John',
56
- * email: 'john@example.com',
57
- * age: 30
58
- * });
59
- * // "INSERT INTO users (name, email, age) VALUES (@name, @email, @age)"
60
- *
61
- * // Note: The actual values will be bound separately using the Parameters object
62
- * ```
63
- */
64
- static BuildInsert(tableName, record) {
65
- const queryParts = [];
66
- const columns = Object.keys(record);
67
- const placeholders = columns.map(col => `@${col}`);
68
- queryParts.push(`INSERT INTO "${tableName}"`);
69
- queryParts.push(`(${columns.map(c => `"${c}"`).join(", ")})`);
70
- queryParts.push(`VALUES (${placeholders.join(", ")})`);
71
- return queryParts.join(" ");
72
- }
73
- /**
74
- * Build an UPDATE SQL statement with SET clause and WHERE conditions
75
- *
76
- * @param table - The table to update
77
- * @param record - Object containing columns to update with their placeholder values
78
- * @param where - Object containing WHERE conditions for targeting specific rows
79
- * @returns Complete UPDATE SQL statement string with @fieldName placeholders
80
- *
81
- * @example
82
- * ```typescript
83
- * const query = QueryStatementBuilder.BuildUpdate(
84
- * usersTable,
85
- * { name: 'John Doe', age: 31 },
86
- * { id: 1 }
87
- * );
88
- * // "UPDATE users SET name = @name, age = @age WHERE id = @id"
89
- *
90
- * // Multiple WHERE conditions
91
- * const query = QueryStatementBuilder.BuildUpdate(
92
- * usersTable,
93
- * { status: 'inactive' },
94
- * { status: 'active', last_login: '2023-01-01' }
95
- * );
96
- * // "UPDATE users SET status = @status WHERE status = @status AND last_login = @last_login"
97
- * ```
98
- */
99
- static BuildUpdate(tableName, record, where) {
100
- const queryParts = [];
101
- const setClauses = Object.keys(record).map(col => `${col} = @${col}`);
102
- queryParts.push(`UPDATE "${tableName}"`);
103
- queryParts.push(`SET ${setClauses.join(", ")}`);
104
- queryParts.push(this.BuildWhere(where).replace(/@(\w+)/g, '@where_$1'));
105
- return queryParts.join(" ");
106
- }
107
- /**
108
- * Build a DELETE SQL statement with WHERE conditions
109
- *
110
- * @param table - The table to delete from
111
- * @param where - Object containing WHERE conditions for targeting specific rows to delete
112
- * @returns Complete DELETE SQL statement string with @fieldName placeholders
113
- *
114
- * @example
115
- * ```typescript
116
- * const query = QueryStatementBuilder.BuildDelete(usersTable, { id: 1 });
117
- * // "DELETE FROM users WHERE id = @id"
118
- *
119
- * // Multiple WHERE conditions
120
- * const query = QueryStatementBuilder.BuildDelete(usersTable, {
121
- * status: 'deleted',
122
- * last_login: '2020-01-01'
123
- * });
124
- * // "DELETE FROM users WHERE status = @status AND last_login = @last_login"
125
- * ```
126
- */
127
- static BuildDelete(tableName, where) {
128
- const queryParts = [];
129
- queryParts.push(`DELETE FROM "${tableName}"`);
130
- queryParts.push(this.BuildWhere(where));
131
- return queryParts.join(" ");
132
- }
133
- /**
134
- * Build a COUNT SQL statement to count rows, optionally with WHERE conditions
135
- *
136
- * @param table - The table to count rows from
137
- * @param where - Optional object containing WHERE conditions to filter counted rows
138
- * @returns Complete COUNT SQL statement string with @fieldName placeholders
139
- *
140
- * @example
141
- * ```typescript
142
- * // Count all rows
143
- * const query = QueryStatementBuilder.BuildCount(usersTable);
144
- * // "SELECT COUNT(*) as count FROM users"
145
- *
146
- * // Count with conditions
147
- * const query = QueryStatementBuilder.BuildCount(usersTable, {
148
- * status: 'active',
149
- * age: 25
150
- * });
151
- * // "SELECT COUNT(*) as count FROM users WHERE status = @status AND age = @age"
152
- * ```
153
- */
154
- static BuildCount(tableName, where) {
155
- const queryParts = [];
156
- queryParts.push(`SELECT COUNT(*) as count FROM "${tableName}"`);
157
- queryParts.push(this.BuildWhere(where));
158
- return queryParts.join(" ");
159
- }
160
- /**
161
- * Build a WHERE clause from parameter conditions (helper method)
162
- *
163
- * Joins multiple conditions with AND operator.
164
- * Returns empty string if no conditions are provided.
165
- *
166
- * @param where - Optional object containing WHERE conditions
167
- * @returns WHERE clause string with @fieldName placeholders, or empty string if no conditions
168
- *
169
- * @example
170
- * ```typescript
171
- * // Single condition
172
- * const whereClause = QueryStatementBuilder.BuildWhere({ id: 1 });
173
- * // "WHERE id = @id"
174
- *
175
- * // Multiple conditions (joined with AND)
176
- * const whereClause = QueryStatementBuilder.BuildWhere({
177
- * status: 'active',
178
- * age: 25,
179
- * role: 'admin'
180
- * });
181
- * // "WHERE status = @status AND age = @age AND role = @role"
182
- *
183
- * // No conditions
184
- * const whereClause = QueryStatementBuilder.BuildWhere();
185
- * // ""
186
- * ```
187
- */
188
- static BuildWhere(where) {
189
- if (!where || (Array.isArray(where) && where.length === 0) || Object.keys(where).length === 0)
190
- return "";
191
- const isSimpleObject = !Array.isArray(where) && typeof where === 'object' && where !== null;
192
- const queryParts = [];
193
- queryParts.push("WHERE");
194
- if (isSimpleObject) {
195
- queryParts.push(this.buildWhereSimple(where));
196
- }
197
- else {
198
- queryParts.push(this.buildWhereWithOperators(where));
199
- }
200
- return queryParts.join(" ");
201
- }
202
- static buildWhereWithOperators(where) {
203
- const queryParts = where.map(condition => {
204
- const operator = condition.operator || "=";
205
- return `${condition.column} ${operator} @${condition.column.trim()}`;
206
- });
207
- return queryParts.join(" AND ");
208
- }
209
- static buildWhereSimple(where) {
210
- const queryParts = Object.keys(where).map(col => `${col} = @${col}`);
211
- return queryParts.join(" AND ");
212
- }
213
- /**
214
- * Build a SELECT statement with JOIN operations (INNER, LEFT, RIGHT, FULL)
215
- *
216
- * Supports single or multiple joins, including nested joins.
217
- * Combines the base SELECT with JOIN clauses and query options.
218
- * The join type (INNER, LEFT, RIGHT, FULL) is specified in each Join object.
219
- *
220
- * @param fromTable - The primary table to select from
221
- * @param joins - Single Join object or array of Join objects defining the join operations
222
- * @param options - Query options including select columns, orderBy, limit, offset
223
- * @returns Complete SELECT statement with JOIN clauses
224
- *
225
- * @example
226
- * ```typescript
227
- * // Single INNER JOIN
228
- * const query = QueryStatementBuilder.BuildJoin(
229
- * usersTable,
230
- * { fromTable: ordersTable, joinType: 'INNER', on: { user_id: 'id' } },
231
- * { select: 'users.*, orders.total' }
232
- * );
233
- * // "SELECT users.*, orders.total FROM users INNER JOIN orders ON users.id = orders.user_id"
234
- *
235
- * // Multiple joins with different types
236
- * const query = QueryStatementBuilder.BuildJoin(
237
- * usersTable,
238
- * [
239
- * { fromTable: ordersTable, joinType: 'INNER', on: { user_id: 'id' } },
240
- * { fromTable: addressesTable, joinType: 'LEFT', on: { address_id: 'id' } }
241
- * ],
242
- * { orderBy: 'users.created_at DESC', limit: 10 }
243
- * );
244
- *
245
- * // Nested JOIN
246
- * const query = QueryStatementBuilder.BuildJoin(
247
- * usersTable,
248
- * {
249
- * fromTable: ordersTable,
250
- * joinType: 'INNER',
251
- * on: { user_id: 'id' },
252
- * join: { fromTable: productsTable, joinType: 'INNER', on: { product_id: 'id' } }
253
- * }
254
- * );
255
- * ```
256
- */
257
- static BuildJoin(fromTableName, joins, query, options) {
258
- return __awaiter(this, void 0, void 0, function* () {
259
- const queryParts = [];
260
- const selectClause = yield QueryStatementBuilder.BuildJoinSelect(fromTableName, joins, query);
261
- queryParts.push(`SELECT ${selectClause}`);
262
- queryParts.push(`FROM "${fromTableName}"`);
263
- queryParts.push(this.BuildJoinPart(fromTableName, joins));
264
- queryParts.push(this.BuildWhere(options === null || options === void 0 ? void 0 : options.where));
265
- queryParts.push(this.BuildQueryOptions(options !== null && options !== void 0 ? options : {}));
266
- return queryParts.join(" ");
267
- });
268
- }
269
- static BuildJoinSelect(fromTableName, joins, query) {
270
- return __awaiter(this, void 0, void 0, function* () {
271
- const mainTableCols = yield query.TableColumnInformation(fromTableName);
272
- const mainTableSelect = mainTableCols.map(col => `"${fromTableName}"."${col.name}" AS "${fromTableName}__${col.name}"`).join(', ');
273
- const joinArray = Array.isArray(joins) ? joins : [joins];
274
- const joinedSelects = yield Promise.all(joinArray.map((join) => __awaiter(this, void 0, void 0, function* () {
275
- const cols = yield query.TableColumnInformation(join.fromTable);
276
- return cols.map(col => `"${join.fromTable}"."${col.name}" AS "${join.fromTable}__${col.name}"`).join(', ');
277
- })));
278
- return [mainTableSelect, ...joinedSelects].join(', ');
279
- });
280
- }
281
- /**
282
- * Build JOIN clause(s) recursively (helper method)
283
- *
284
- * Processes single or multiple join definitions and handles nested joins.
285
- * Each join includes the JOIN clause (INNER, LEFT, RIGHT, FULL) and ON conditions.
286
- *
287
- * @param fromTable - The table being joined from (for ON clause context)
288
- * @param joins - Single Join object or array of Join objects
289
- * @returns JOIN clause(s) as a string
290
- *
291
- * @example
292
- * ```typescript
293
- * // Single INNER JOIN
294
- * const joinClause = QueryStatementBuilder.BuildJoinPart(
295
- * usersTable,
296
- * { fromTable: ordersTable, joinType: 'INNER', on: { user_id: 'id' } }
297
- * );
298
- * // "INNER JOIN orders ON users.id = orders.user_id"
299
- *
300
- * // LEFT JOIN
301
- * const joinClause = QueryStatementBuilder.BuildJoinPart(
302
- * usersTable,
303
- * { fromTable: profilesTable, joinType: 'LEFT', on: { profile_id: 'id' } }
304
- * );
305
- * // "LEFT JOIN profiles ON users.id = profiles.profile_id"
306
- *
307
- * // Nested join
308
- * const joinClause = QueryStatementBuilder.BuildJoinPart(
309
- * usersTable,
310
- * {
311
- * fromTable: ordersTable,
312
- * joinType: 'INNER',
313
- * on: { user_id: 'id' },
314
- * join: { fromTable: productsTable, joinType: 'INNER', on: { product_id: 'id' } }
315
- * }
316
- * );
317
- * // "INNER JOIN orders ON users.id = orders.user_id INNER JOIN products ON orders.id = products.product_id"
318
- * ```
319
- */
320
- static BuildJoinPart(fromTableName, joins) {
321
- const queryParts = [];
322
- joins = Array.isArray(joins) ? joins : [joins];
323
- for (const join of joins) {
324
- const baseTable = join.baseTable || fromTableName; // Use explicit base or default
325
- queryParts.push(`${join.joinType} JOIN "${join.fromTable}"`);
326
- queryParts.push(this.BuildJoinOnPart(baseTable, join.fromTable, join.on));
327
- }
328
- return queryParts.join(" ");
329
- }
330
- /**
331
- * Build ON clause for JOIN operations (helper method)
332
- *
333
- * Creates ON conditions for join operations.
334
- * Compares the foreign key column in the joined table with the primary key in the source table.
335
- * Multiple conditions are joined with AND operator.
336
- *
337
- * @param table - The source table (left side of the join)
338
- * @param joinTable - The table being joined (right side of the join)
339
- * @param on - QueryCondition object where key is the foreign key in joinTable and value is the primary key in table
340
- * @returns ON clause string for JOIN operations
341
- *
342
- * @example
343
- * ```typescript
344
- * // Single ON condition
345
- * // Key: column in joinTable (orders), Value: column in table (users)
346
- * const onClause = QueryStatementBuilder.BuildJoinOnPart(
347
- * usersTable,
348
- * ordersTable,
349
- * { user_id: 'id' }
350
- * );
351
- * // "ON users.id = orders.user_id"
352
- *
353
- * // Multiple ON conditions
354
- * const onClause = QueryStatementBuilder.BuildJoinOnPart(
355
- * usersTable,
356
- * ordersTable,
357
- * [{ user_id: 'id' }, { company_id: 'company_id' }]
358
- * );
359
- * // "ON users.id = orders.user_id AND users.company_id = orders.company_id"
360
- * ```
361
- */
362
- static BuildJoinOnPart(tableName, joinTableName, on) {
363
- const queryParts = [];
364
- const onArray = Array.isArray(on) ? on : [on];
365
- for (const onPart of onArray) {
366
- queryParts.push(`ON ${tableName}.${Object.values(onPart)[0]} = ${joinTableName}.${Object.keys(onPart)[0]}`);
367
- }
368
- return queryParts.join(" AND ");
369
- }
370
- /**
371
- * Build query options clause (ORDER BY, LIMIT, OFFSET) (helper method)
372
- *
373
- * Processes query options and builds the corresponding SQL clauses.
374
- * Returns empty string if no options are provided.
375
- *
376
- * @param options - Object containing orderBy, limit, and/or offset options
377
- * @returns Query options clause as a string
378
- *
379
- * @example
380
- * ```typescript
381
- * // All options
382
- * const optionsClause = QueryStatementBuilder.BuildQueryOptions({
383
- * orderBy: 'created_at DESC',
384
- * limit: 10,
385
- * offset: 20
386
- * });
387
- * // "ORDER BY created_at DESC LIMIT 10 OFFSET 20"
388
- *
389
- * // Just ordering
390
- * const optionsClause = QueryStatementBuilder.BuildQueryOptions({
391
- * orderBy: 'name ASC'
392
- * });
393
- * // "ORDER BY name ASC"
394
- *
395
- * // Pagination only
396
- * const optionsClause = QueryStatementBuilder.BuildQueryOptions({
397
- * limit: 25,
398
- * offset: 50
399
- * });
400
- * // "LIMIT 25 OFFSET 50"
401
- * ```
402
- */
403
- static BuildQueryOptions(options) {
404
- const queryParts = [];
405
- if (options === null || options === void 0 ? void 0 : options.orderBy) {
406
- queryParts.push(`ORDER BY ${options.orderBy}`);
407
- }
408
- if (options === null || options === void 0 ? void 0 : options.limit) {
409
- queryParts.push(`LIMIT ${options.limit}`);
410
- if (options === null || options === void 0 ? void 0 : options.offset) {
411
- queryParts.push(`OFFSET ${options.offset}`);
412
- }
413
- }
414
- return queryParts.join(" ");
415
- }
416
- }