@iamkirbki/database-handler-core 4.3.0 → 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.
- package/dist/abstract/Controller.d.ts +17 -0
- package/dist/abstract/Controller.d.ts.map +1 -0
- package/dist/abstract/Controller.js +47 -0
- package/dist/abstract/Model.d.ts +33 -19
- package/dist/abstract/Model.d.ts.map +1 -1
- package/dist/abstract/Model.js +177 -120
- package/dist/abstract/SchemaTableBuilder.d.ts +1 -1
- package/dist/abstract/SchemaTableBuilder.d.ts.map +1 -1
- package/dist/abstract/model/ModelRelation.d.ts +23 -0
- package/dist/abstract/model/ModelRelation.d.ts.map +1 -0
- package/dist/abstract/model/ModelRelation.js +130 -0
- package/dist/base/Query.d.ts +10 -13
- package/dist/base/Query.d.ts.map +1 -1
- package/dist/base/Query.js +68 -26
- package/dist/base/Record.d.ts +4 -2
- package/dist/base/Record.d.ts.map +1 -1
- package/dist/base/Record.js +24 -14
- package/dist/base/Table.d.ts +12 -7
- package/dist/base/Table.d.ts.map +1 -1
- package/dist/base/Table.js +87 -47
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.d.ts +4 -0
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.d.ts.map +1 -0
- package/dist/helpers/Errors/AdapterErrors/AdapterNotFoundError.js +6 -0
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.d.ts +4 -0
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.d.ts.map +1 -0
- package/dist/helpers/Errors/AdapterErrors/ConnectionFailedError.js +6 -0
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.d.ts +4 -0
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.d.ts.map +1 -0
- package/dist/helpers/Errors/AdapterErrors/NoDefaultAdapterError.js +6 -0
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.d.ts +4 -0
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.d.ts.map +1 -0
- package/dist/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.js +6 -0
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.d.ts +4 -0
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.d.ts.map +1 -0
- package/dist/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.js +6 -0
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.d.ts +4 -0
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.d.ts.map +1 -0
- package/dist/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.js +6 -0
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.d.ts +4 -0
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.d.ts.map +1 -0
- package/dist/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.js +6 -0
- package/dist/helpers/Errors/TableErrors/UnknownTableError.d.ts +4 -0
- package/dist/helpers/Errors/TableErrors/UnknownTableError.d.ts.map +1 -0
- package/dist/helpers/Errors/TableErrors/UnknownTableError.js +6 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseDeleteQueryBuilder.d.ts +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseDeleteQueryBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseDeleteQueryBuilder.js +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseInsertQueryBuilder.d.ts +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseInsertQueryBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseInsertQueryBuilder.js +11 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.d.ts +11 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.js +27 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseUpdateQueryBuilder.d.ts +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseUpdateQueryBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseUpdateQueryBuilder.js +1 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.d.ts +9 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.js +102 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.d.ts +8 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.js +63 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.d.ts +8 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/ExpressionBuilders/TextRelevanceExpression.js +49 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.d.ts +19 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.js +60 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.d.ts +9 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.js +27 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.d.ts +15 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.js +74 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.d.ts +10 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.js +29 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.d.ts +9 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.js +27 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.d.ts +8 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/QueryDecorator.js +5 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ValuesDecorator.d.ts +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ValuesDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/ValuesDecorator.js +17 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.d.ts +9 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.js +29 -0
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.d.ts +54 -0
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryExpressionBuilder.js +102 -0
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.d.ts +16 -0
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.js +169 -0
- package/dist/helpers/QueryBuilders/SqlRenderer.d.ts +15 -0
- package/dist/helpers/QueryBuilders/SqlRenderer.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/SqlRenderer.js +79 -0
- package/dist/helpers/QueryBuilders/oldQueryStatementBuilder.d.ts +160 -0
- package/dist/helpers/QueryBuilders/oldQueryStatementBuilder.d.ts.map +1 -0
- package/dist/helpers/QueryBuilders/oldQueryStatementBuilder.js +217 -0
- package/dist/interfaces/IExpressionBuilder.d.ts +7 -0
- package/dist/interfaces/IExpressionBuilder.d.ts.map +1 -0
- package/dist/interfaces/IExpressionBuilder.js +1 -0
- package/dist/interfaces/IQueryBuilder.d.ts +5 -0
- package/dist/interfaces/IQueryBuilder.d.ts.map +1 -0
- package/dist/interfaces/IQueryBuilder.js +1 -0
- package/dist/interfaces/ISchemaBuilder.d.ts +1 -1
- package/dist/interfaces/ISchemaBuilder.d.ts.map +1 -1
- package/dist/runtime/Container.d.ts +3 -0
- package/dist/runtime/Container.d.ts.map +1 -1
- package/dist/runtime/Container.js +12 -2
- package/dist/runtime/QueryCache.d.ts +12 -0
- package/dist/runtime/QueryCache.d.ts.map +1 -0
- package/dist/runtime/QueryCache.js +26 -0
- package/dist/runtime/Repository.d.ts +13 -7
- package/dist/runtime/Repository.d.ts.map +1 -1
- package/dist/runtime/Repository.js +114 -70
- package/dist/types/expressions.d.ts +154 -0
- package/dist/types/expressions.d.ts.map +1 -0
- package/dist/types/expressions.js +6 -0
- package/dist/types/factories.d.ts +7 -0
- package/dist/types/factories.d.ts.map +1 -0
- package/dist/types/factories.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/model.d.ts +8 -8
- package/dist/types/model.d.ts.map +1 -1
- package/dist/types/query.d.ts +63 -1
- package/dist/types/query.d.ts.map +1 -1
- package/package.json +11 -3
- package/dist/helpers/QueryStatementBuilder.d.ts +0 -304
- package/dist/helpers/QueryStatementBuilder.d.ts.map +0 -1
- package/dist/helpers/QueryStatementBuilder.js +0 -417
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import { DefaultQueryParameters, ExtraQueryParameters, QueryWhereCondition, Join, QueryIsEqualParameter } from "../types/index.js";
|
|
2
|
-
/** Utility class for building SQL query strings */
|
|
3
|
-
export default class QueryStatementBuilder {
|
|
4
|
-
/**
|
|
5
|
-
* Build a SELECT SQL statement with optional filtering, ordering, and pagination
|
|
6
|
-
*
|
|
7
|
-
* @param table - The table to select from
|
|
8
|
-
* @param options - Query options including select columns, where conditions, orderBy, limit, offset
|
|
9
|
-
* @returns Complete SELECT SQL statement string
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* // Select all columns
|
|
14
|
-
* const query = QueryStatementBuilder.BuildSelect(usersTable);
|
|
15
|
-
* // "SELECT * FROM users"
|
|
16
|
-
*
|
|
17
|
-
* // Select specific columns with filtering
|
|
18
|
-
* const query = QueryStatementBuilder.BuildSelect(usersTable, {
|
|
19
|
-
* select: 'id, name, email',
|
|
20
|
-
* where: { status: 'active', age: 25 },
|
|
21
|
-
* orderBy: 'created_at DESC',
|
|
22
|
-
* limit: 10,
|
|
23
|
-
* offset: 20
|
|
24
|
-
* });
|
|
25
|
-
* // "SELECT id, name, email FROM users WHERE status = @status AND age = @age ORDER BY created_at DESC LIMIT 10 OFFSET 20"
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
static BuildSelect(tableName: string, options?: DefaultQueryParameters & ExtraQueryParameters): string;
|
|
29
|
-
/**
|
|
30
|
-
* Build an INSERT SQL statement with named parameter placeholders
|
|
31
|
-
*
|
|
32
|
-
* @param table - The table to insert into
|
|
33
|
-
* @param record - Object containing column names and their placeholder values
|
|
34
|
-
* @returns Complete INSERT SQL statement string with @fieldName placeholders
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* const query = QueryStatementBuilder.BuildInsert(usersTable, {
|
|
39
|
-
* name: 'John',
|
|
40
|
-
* email: 'john@example.com',
|
|
41
|
-
* age: 30
|
|
42
|
-
* });
|
|
43
|
-
* // "INSERT INTO users (name, email, age) VALUES (@name, @email, @age)"
|
|
44
|
-
*
|
|
45
|
-
* // Note: The actual values will be bound separately using the Parameters object
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
static BuildInsert(tableName: string, record: QueryIsEqualParameter): string;
|
|
49
|
-
/**
|
|
50
|
-
* Build an UPDATE SQL statement with SET clause and WHERE conditions
|
|
51
|
-
*
|
|
52
|
-
* @param table - The table to update
|
|
53
|
-
* @param record - Object containing columns to update with their placeholder values
|
|
54
|
-
* @param where - Object containing WHERE conditions for targeting specific rows
|
|
55
|
-
* @returns Complete UPDATE SQL statement string with @fieldName placeholders
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```typescript
|
|
59
|
-
* const query = QueryStatementBuilder.BuildUpdate(
|
|
60
|
-
* usersTable,
|
|
61
|
-
* { name: 'John Doe', age: 31 },
|
|
62
|
-
* { id: 1 }
|
|
63
|
-
* );
|
|
64
|
-
* // "UPDATE users SET name = @name, age = @age WHERE id = @id"
|
|
65
|
-
*
|
|
66
|
-
* // Multiple WHERE conditions
|
|
67
|
-
* const query = QueryStatementBuilder.BuildUpdate(
|
|
68
|
-
* usersTable,
|
|
69
|
-
* { status: 'inactive' },
|
|
70
|
-
* { status: 'active', last_login: '2023-01-01' }
|
|
71
|
-
* );
|
|
72
|
-
* // "UPDATE users SET status = @status WHERE status = @status AND last_login = @last_login"
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
static BuildUpdate(tableName: string, record: QueryWhereCondition, where: QueryWhereCondition): string;
|
|
76
|
-
/**
|
|
77
|
-
* Build a DELETE SQL statement with WHERE conditions
|
|
78
|
-
*
|
|
79
|
-
* @param table - The table to delete from
|
|
80
|
-
* @param where - Object containing WHERE conditions for targeting specific rows to delete
|
|
81
|
-
* @returns Complete DELETE SQL statement string with @fieldName placeholders
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```typescript
|
|
85
|
-
* const query = QueryStatementBuilder.BuildDelete(usersTable, { id: 1 });
|
|
86
|
-
* // "DELETE FROM users WHERE id = @id"
|
|
87
|
-
*
|
|
88
|
-
* // Multiple WHERE conditions
|
|
89
|
-
* const query = QueryStatementBuilder.BuildDelete(usersTable, {
|
|
90
|
-
* status: 'deleted',
|
|
91
|
-
* last_login: '2020-01-01'
|
|
92
|
-
* });
|
|
93
|
-
* // "DELETE FROM users WHERE status = @status AND last_login = @last_login"
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
static BuildDelete(tableName: string, where: QueryWhereCondition): string;
|
|
97
|
-
/**
|
|
98
|
-
* Build a COUNT SQL statement to count rows, optionally with WHERE conditions
|
|
99
|
-
*
|
|
100
|
-
* @param table - The table to count rows from
|
|
101
|
-
* @param where - Optional object containing WHERE conditions to filter counted rows
|
|
102
|
-
* @returns Complete COUNT SQL statement string with @fieldName placeholders
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* ```typescript
|
|
106
|
-
* // Count all rows
|
|
107
|
-
* const query = QueryStatementBuilder.BuildCount(usersTable);
|
|
108
|
-
* // "SELECT COUNT(*) as count FROM users"
|
|
109
|
-
*
|
|
110
|
-
* // Count with conditions
|
|
111
|
-
* const query = QueryStatementBuilder.BuildCount(usersTable, {
|
|
112
|
-
* status: 'active',
|
|
113
|
-
* age: 25
|
|
114
|
-
* });
|
|
115
|
-
* // "SELECT COUNT(*) as count FROM users WHERE status = @status AND age = @age"
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
static BuildCount(tableName: string, where?: QueryWhereCondition): string;
|
|
119
|
-
/**
|
|
120
|
-
* Build a WHERE clause from parameter conditions (helper method)
|
|
121
|
-
*
|
|
122
|
-
* Joins multiple conditions with AND operator.
|
|
123
|
-
* Returns empty string if no conditions are provided.
|
|
124
|
-
*
|
|
125
|
-
* @param where - Optional object containing WHERE conditions
|
|
126
|
-
* @returns WHERE clause string with @fieldName placeholders, or empty string if no conditions
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```typescript
|
|
130
|
-
* // Single condition
|
|
131
|
-
* const whereClause = QueryStatementBuilder.BuildWhere({ id: 1 });
|
|
132
|
-
* // "WHERE id = @id"
|
|
133
|
-
*
|
|
134
|
-
* // Multiple conditions (joined with AND)
|
|
135
|
-
* const whereClause = QueryStatementBuilder.BuildWhere({
|
|
136
|
-
* status: 'active',
|
|
137
|
-
* age: 25,
|
|
138
|
-
* role: 'admin'
|
|
139
|
-
* });
|
|
140
|
-
* // "WHERE status = @status AND age = @age AND role = @role"
|
|
141
|
-
*
|
|
142
|
-
* // No conditions
|
|
143
|
-
* const whereClause = QueryStatementBuilder.BuildWhere();
|
|
144
|
-
* // ""
|
|
145
|
-
* ```
|
|
146
|
-
*/
|
|
147
|
-
static BuildWhere(where?: QueryWhereCondition): string;
|
|
148
|
-
private static buildWhereWithOperators;
|
|
149
|
-
private static buildWhereSimple;
|
|
150
|
-
/**
|
|
151
|
-
* Build a SELECT statement with JOIN operations (INNER, LEFT, RIGHT, FULL)
|
|
152
|
-
*
|
|
153
|
-
* Supports single or multiple joins, including nested joins.
|
|
154
|
-
* Combines the base SELECT with JOIN clauses and query options.
|
|
155
|
-
* The join type (INNER, LEFT, RIGHT, FULL) is specified in each Join object.
|
|
156
|
-
*
|
|
157
|
-
* @param fromTable - The primary table to select from
|
|
158
|
-
* @param joins - Single Join object or array of Join objects defining the join operations
|
|
159
|
-
* @param options - Query options including select columns, orderBy, limit, offset
|
|
160
|
-
* @returns Complete SELECT statement with JOIN clauses
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
163
|
-
* ```typescript
|
|
164
|
-
* // Single INNER JOIN
|
|
165
|
-
* const query = QueryStatementBuilder.BuildJoin(
|
|
166
|
-
* usersTable,
|
|
167
|
-
* { fromTable: ordersTable, joinType: 'INNER', on: { user_id: 'id' } },
|
|
168
|
-
* { select: 'users.*, orders.total' }
|
|
169
|
-
* );
|
|
170
|
-
* // "SELECT users.*, orders.total FROM users INNER JOIN orders ON users.id = orders.user_id"
|
|
171
|
-
*
|
|
172
|
-
* // Multiple joins with different types
|
|
173
|
-
* const query = QueryStatementBuilder.BuildJoin(
|
|
174
|
-
* usersTable,
|
|
175
|
-
* [
|
|
176
|
-
* { fromTable: ordersTable, joinType: 'INNER', on: { user_id: 'id' } },
|
|
177
|
-
* { fromTable: addressesTable, joinType: 'LEFT', on: { address_id: 'id' } }
|
|
178
|
-
* ],
|
|
179
|
-
* { orderBy: 'users.created_at DESC', limit: 10 }
|
|
180
|
-
* );
|
|
181
|
-
*
|
|
182
|
-
* // Nested JOIN
|
|
183
|
-
* const query = QueryStatementBuilder.BuildJoin(
|
|
184
|
-
* usersTable,
|
|
185
|
-
* {
|
|
186
|
-
* fromTable: ordersTable,
|
|
187
|
-
* joinType: 'INNER',
|
|
188
|
-
* on: { user_id: 'id' },
|
|
189
|
-
* join: { fromTable: productsTable, joinType: 'INNER', on: { product_id: 'id' } }
|
|
190
|
-
* }
|
|
191
|
-
* );
|
|
192
|
-
* ```
|
|
193
|
-
*/
|
|
194
|
-
static BuildJoin(fromTableName: string, joins: Join | Join[], options?: DefaultQueryParameters & ExtraQueryParameters): Promise<string>;
|
|
195
|
-
static BuildJoinSelect(fromTableName: string, joins: Join | Join[]): Promise<string>;
|
|
196
|
-
/**
|
|
197
|
-
* Build JOIN clause(s) recursively (helper method)
|
|
198
|
-
*
|
|
199
|
-
* Processes single or multiple join definitions and handles nested joins.
|
|
200
|
-
* Each join includes the JOIN clause (INNER, LEFT, RIGHT, FULL) and ON conditions.
|
|
201
|
-
*
|
|
202
|
-
* @param fromTable - The table being joined from (for ON clause context)
|
|
203
|
-
* @param joins - Single Join object or array of Join objects
|
|
204
|
-
* @returns JOIN clause(s) as a string
|
|
205
|
-
*
|
|
206
|
-
* @example
|
|
207
|
-
* ```typescript
|
|
208
|
-
* // Single INNER JOIN
|
|
209
|
-
* const joinClause = QueryStatementBuilder.BuildJoinPart(
|
|
210
|
-
* usersTable,
|
|
211
|
-
* { fromTable: ordersTable, joinType: 'INNER', on: { user_id: 'id' } }
|
|
212
|
-
* );
|
|
213
|
-
* // "INNER JOIN orders ON users.id = orders.user_id"
|
|
214
|
-
*
|
|
215
|
-
* // LEFT JOIN
|
|
216
|
-
* const joinClause = QueryStatementBuilder.BuildJoinPart(
|
|
217
|
-
* usersTable,
|
|
218
|
-
* { fromTable: profilesTable, joinType: 'LEFT', on: { profile_id: 'id' } }
|
|
219
|
-
* );
|
|
220
|
-
* // "LEFT JOIN profiles ON users.id = profiles.profile_id"
|
|
221
|
-
*
|
|
222
|
-
* // Nested join
|
|
223
|
-
* const joinClause = QueryStatementBuilder.BuildJoinPart(
|
|
224
|
-
* usersTable,
|
|
225
|
-
* {
|
|
226
|
-
* fromTable: ordersTable,
|
|
227
|
-
* joinType: 'INNER',
|
|
228
|
-
* on: { user_id: 'id' },
|
|
229
|
-
* join: { fromTable: productsTable, joinType: 'INNER', on: { product_id: 'id' } }
|
|
230
|
-
* }
|
|
231
|
-
* );
|
|
232
|
-
* // "INNER JOIN orders ON users.id = orders.user_id INNER JOIN products ON orders.id = products.product_id"
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
static BuildJoinPart(fromTableName: string, joins: Join | Join[]): string;
|
|
236
|
-
/**
|
|
237
|
-
* Build ON clause for JOIN operations (helper method)
|
|
238
|
-
*
|
|
239
|
-
* Creates ON conditions for join operations.
|
|
240
|
-
* Compares the foreign key column in the joined table with the primary key in the source table.
|
|
241
|
-
* Multiple conditions are joined with AND operator.
|
|
242
|
-
*
|
|
243
|
-
* @param table - The source table (left side of the join)
|
|
244
|
-
* @param joinTable - The table being joined (right side of the join)
|
|
245
|
-
* @param on - QueryCondition object where key is the foreign key in joinTable and value is the primary key in table
|
|
246
|
-
* @returns ON clause string for JOIN operations
|
|
247
|
-
*
|
|
248
|
-
* @example
|
|
249
|
-
* ```typescript
|
|
250
|
-
* // Single ON condition
|
|
251
|
-
* // Key: column in joinTable (orders), Value: column in table (users)
|
|
252
|
-
* const onClause = QueryStatementBuilder.BuildJoinOnPart(
|
|
253
|
-
* usersTable,
|
|
254
|
-
* ordersTable,
|
|
255
|
-
* { user_id: 'id' }
|
|
256
|
-
* );
|
|
257
|
-
* // "ON users.id = orders.user_id"
|
|
258
|
-
*
|
|
259
|
-
* // Multiple ON conditions
|
|
260
|
-
* const onClause = QueryStatementBuilder.BuildJoinOnPart(
|
|
261
|
-
* usersTable,
|
|
262
|
-
* ordersTable,
|
|
263
|
-
* [{ user_id: 'id' }, { company_id: 'company_id' }]
|
|
264
|
-
* );
|
|
265
|
-
* // "ON users.id = orders.user_id AND users.company_id = orders.company_id"
|
|
266
|
-
* ```
|
|
267
|
-
*/
|
|
268
|
-
static BuildJoinOnPart(tableName: string, joinTableName: string, on: QueryIsEqualParameter | QueryIsEqualParameter[]): string;
|
|
269
|
-
/**
|
|
270
|
-
* Build query options clause (ORDER BY, LIMIT, OFFSET) (helper method)
|
|
271
|
-
*
|
|
272
|
-
* Processes query options and builds the corresponding SQL clauses.
|
|
273
|
-
* Returns empty string if no options are provided.
|
|
274
|
-
*
|
|
275
|
-
* @param options - Object containing orderBy, limit, and/or offset options
|
|
276
|
-
* @returns Query options clause as a string
|
|
277
|
-
*
|
|
278
|
-
* @example
|
|
279
|
-
* ```typescript
|
|
280
|
-
* // All options
|
|
281
|
-
* const optionsClause = QueryStatementBuilder.BuildQueryOptions({
|
|
282
|
-
* orderBy: 'created_at DESC',
|
|
283
|
-
* limit: 10,
|
|
284
|
-
* offset: 20
|
|
285
|
-
* });
|
|
286
|
-
* // "ORDER BY created_at DESC LIMIT 10 OFFSET 20"
|
|
287
|
-
*
|
|
288
|
-
* // Just ordering
|
|
289
|
-
* const optionsClause = QueryStatementBuilder.BuildQueryOptions({
|
|
290
|
-
* orderBy: 'name ASC'
|
|
291
|
-
* });
|
|
292
|
-
* // "ORDER BY name ASC"
|
|
293
|
-
*
|
|
294
|
-
* // Pagination only
|
|
295
|
-
* const optionsClause = QueryStatementBuilder.BuildQueryOptions({
|
|
296
|
-
* limit: 25,
|
|
297
|
-
* offset: 50
|
|
298
|
-
* });
|
|
299
|
-
* // "LIMIT 25 OFFSET 50"
|
|
300
|
-
* ```
|
|
301
|
-
*/
|
|
302
|
-
static BuildQueryOptions(options: ExtraQueryParameters): string;
|
|
303
|
-
}
|
|
304
|
-
//# sourceMappingURL=QueryStatementBuilder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"QueryStatementBuilder.d.ts","sourceRoot":"","sources":["../../src/helpers/QueryStatementBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,IAAI,EAA6B,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAEjK,mDAAmD;AACnD,MAAM,CAAC,OAAO,OAAO,qBAAqB;IACtC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;WACW,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,oBAAoB,GAAG,MAAM;IAW7G;;;;;;;;;;;;;;;;;;OAkBG;WACW,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,qBAAqB,GAAG,MAAM;IAYnF;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;WACW,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,EAAE,KAAK,EAAE,mBAAmB,GAAG,MAAM;IAW7G;;;;;;;;;;;;;;;;;;;OAmBG;WACW,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,MAAM;IAShF;;;;;;;;;;;;;;;;;;;;OAoBG;WACW,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,mBAAmB,GAAG,MAAM;IAQhF;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;WACW,UAAU,CAAC,KAAK,CAAC,EAAE,mBAAmB,GAAG,MAAM;IAgB7D,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAStC,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAK/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;WACiB,SAAS,CACzB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,EACpB,OAAO,CAAC,EAAE,sBAAsB,GAAG,oBAAoB,GACxD,OAAO,CAAC,MAAM,CAAC;WAaE,eAAe,CAC/B,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,GACrB,OAAO,CAAC,MAAM,CAAC;IAmBlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;WACW,aAAa,CACvB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,GACrB,MAAM;IAaT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;WACW,eAAe,CACzB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,EAAE,EAAE,qBAAqB,GAAG,qBAAqB,EAAE,GACpD,MAAM;IAWT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;WACW,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM;CAiBzE"}
|