@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
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/** Utility class for building SQL query strings */
|
|
2
|
+
export default class oldQueryStatementBuilder {
|
|
3
|
+
/**
|
|
4
|
+
* Build an INSERT SQL statement with named parameter placeholders
|
|
5
|
+
*
|
|
6
|
+
* @param table - The table to insert into
|
|
7
|
+
* @param record - Object containing column names and their placeholder values
|
|
8
|
+
* @returns Complete INSERT SQL statement string with @fieldName placeholders
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const query = QueryStatementBuilder.BuildInsert(usersTable, {
|
|
13
|
+
* name: 'John',
|
|
14
|
+
* email: 'john@example.com',
|
|
15
|
+
* age: 30
|
|
16
|
+
* });
|
|
17
|
+
* // "INSERT INTO users (name, email, age) VALUES (@name, @email, @age)"
|
|
18
|
+
*
|
|
19
|
+
* // Note: The actual values will be bound separately using the Parameters object
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
static BuildInsert(tableName, record) {
|
|
23
|
+
const queryParts = [];
|
|
24
|
+
const columns = Object.keys(record);
|
|
25
|
+
const placeholders = columns.map(col => `@${col}`);
|
|
26
|
+
queryParts.push(`INSERT INTO "${tableName}"`);
|
|
27
|
+
queryParts.push(`(${columns.map(c => `"${c}"`).join(", ")})`);
|
|
28
|
+
queryParts.push(`VALUES (${placeholders.join(", ")})`);
|
|
29
|
+
return queryParts.join(" ");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Build an UPDATE SQL statement with SET clause and WHERE conditions
|
|
33
|
+
*
|
|
34
|
+
* @param table - The table to update
|
|
35
|
+
* @param record - Object containing columns to update with their placeholder values
|
|
36
|
+
* @param where - Object containing WHERE conditions for targeting specific rows
|
|
37
|
+
* @returns Complete UPDATE SQL statement string with @fieldName placeholders
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const query = QueryStatementBuilder.BuildUpdate(
|
|
42
|
+
* usersTable,
|
|
43
|
+
* { name: 'John Doe', age: 31 },
|
|
44
|
+
* { id: 1 }
|
|
45
|
+
* );
|
|
46
|
+
* // "UPDATE users SET name = @name, age = @age WHERE id = @id"
|
|
47
|
+
*
|
|
48
|
+
* // Multiple WHERE conditions
|
|
49
|
+
* const query = QueryStatementBuilder.BuildUpdate(
|
|
50
|
+
* usersTable,
|
|
51
|
+
* { status: 'inactive' },
|
|
52
|
+
* { status: 'active', last_login: '2023-01-01' }
|
|
53
|
+
* );
|
|
54
|
+
* // "UPDATE users SET status = @status WHERE status = @status AND last_login = @last_login"
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
static BuildUpdate(tableName, record, where) {
|
|
58
|
+
const queryParts = [];
|
|
59
|
+
const setClauses = Object.keys(record).map(col => `${col} = @${col}`);
|
|
60
|
+
queryParts.push(`UPDATE "${tableName}"`);
|
|
61
|
+
queryParts.push(`SET ${setClauses.join(", ")}`);
|
|
62
|
+
queryParts.push(this.BuildWhere(where).replace(/@(\w+)/g, '@where_$1'));
|
|
63
|
+
return queryParts.join(" ");
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Build a DELETE SQL statement with WHERE conditions
|
|
67
|
+
*
|
|
68
|
+
* @param table - The table to delete from
|
|
69
|
+
* @param where - Object containing WHERE conditions for targeting specific rows to delete
|
|
70
|
+
* @returns Complete DELETE SQL statement string with @fieldName placeholders
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const query = QueryStatementBuilder.BuildDelete(usersTable, { id: 1 });
|
|
75
|
+
* // "DELETE FROM users WHERE id = @id"
|
|
76
|
+
*
|
|
77
|
+
* // Multiple WHERE conditions
|
|
78
|
+
* const query = QueryStatementBuilder.BuildDelete(usersTable, {
|
|
79
|
+
* status: 'deleted',
|
|
80
|
+
* last_login: '2020-01-01'
|
|
81
|
+
* });
|
|
82
|
+
* // "DELETE FROM users WHERE status = @status AND last_login = @last_login"
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
static BuildDelete(tableName, where) {
|
|
86
|
+
const queryParts = [];
|
|
87
|
+
queryParts.push(`DELETE FROM "${tableName}"`);
|
|
88
|
+
queryParts.push(this.BuildWhere(where));
|
|
89
|
+
return queryParts.join(" ");
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Build a COUNT SQL statement to count rows, optionally with WHERE conditions
|
|
93
|
+
*
|
|
94
|
+
* @param table - The table to count rows from
|
|
95
|
+
* @param where - Optional object containing WHERE conditions to filter counted rows
|
|
96
|
+
* @returns Complete COUNT SQL statement string with @fieldName placeholders
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* // Count all rows
|
|
101
|
+
* const query = QueryStatementBuilder.BuildCount(usersTable);
|
|
102
|
+
* // "SELECT COUNT(*) as count FROM users"
|
|
103
|
+
*
|
|
104
|
+
* // Count with conditions
|
|
105
|
+
* const query = QueryStatementBuilder.BuildCount(usersTable, {
|
|
106
|
+
* status: 'active',
|
|
107
|
+
* age: 25
|
|
108
|
+
* });
|
|
109
|
+
* // "SELECT COUNT(*) as count FROM users WHERE status = @status AND age = @age"
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
static BuildCount(tableName, where) {
|
|
113
|
+
const queryParts = [];
|
|
114
|
+
queryParts.push(`SELECT COUNT(*) as count FROM "${tableName}"`);
|
|
115
|
+
queryParts.push(this.BuildWhere(where));
|
|
116
|
+
return queryParts.join(" ");
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Build a WHERE clause from parameter conditions (helper method)
|
|
120
|
+
*
|
|
121
|
+
* Joins multiple conditions with AND operator.
|
|
122
|
+
* Returns empty string if no conditions are provided.
|
|
123
|
+
*
|
|
124
|
+
* @param where - Optional object containing WHERE conditions
|
|
125
|
+
* @returns WHERE clause string with @fieldName placeholders, or empty string if no conditions
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // Single condition
|
|
130
|
+
* const whereClause = QueryStatementBuilder.BuildWhere({ id: 1 });
|
|
131
|
+
* // "WHERE id = @id"
|
|
132
|
+
*
|
|
133
|
+
* // Multiple conditions (joined with AND)
|
|
134
|
+
* const whereClause = QueryStatementBuilder.BuildWhere({
|
|
135
|
+
* status: 'active',
|
|
136
|
+
* age: 25,
|
|
137
|
+
* role: 'admin'
|
|
138
|
+
* });
|
|
139
|
+
* // "WHERE status = @status AND age = @age AND role = @role"
|
|
140
|
+
*
|
|
141
|
+
* // No conditions
|
|
142
|
+
* const whereClause = QueryStatementBuilder.BuildWhere();
|
|
143
|
+
* // ""
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
static BuildWhere(where) {
|
|
147
|
+
if (!where || (Array.isArray(where) && where.length === 0) || Object.keys(where).length === 0)
|
|
148
|
+
return "";
|
|
149
|
+
const isSimpleObject = !Array.isArray(where) && typeof where === 'object' && where !== null;
|
|
150
|
+
const queryParts = [];
|
|
151
|
+
queryParts.push("WHERE");
|
|
152
|
+
if (isSimpleObject) {
|
|
153
|
+
queryParts.push(this.buildWhereSimple(where));
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
queryParts.push(this.buildWhereWithOperators(where));
|
|
157
|
+
}
|
|
158
|
+
return queryParts.join(" ");
|
|
159
|
+
}
|
|
160
|
+
static buildWhereWithOperators(where) {
|
|
161
|
+
const queryParts = where.map(condition => {
|
|
162
|
+
const operator = condition.operator || "=";
|
|
163
|
+
return `${condition.column} ${operator} @${condition.column.trim()}`;
|
|
164
|
+
});
|
|
165
|
+
return queryParts.join(" AND ");
|
|
166
|
+
}
|
|
167
|
+
static buildWhereSimple(where) {
|
|
168
|
+
const queryParts = Object.keys(where).map(col => `${col} = @${col}`);
|
|
169
|
+
return queryParts.join(" AND ");
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Build query options clause (ORDER BY, LIMIT, OFFSET) (helper method)
|
|
173
|
+
*
|
|
174
|
+
* Processes query options and builds the corresponding SQL clauses.
|
|
175
|
+
* Returns empty string if no options are provided.
|
|
176
|
+
*
|
|
177
|
+
* @param options - Object containing orderBy, limit, and/or offset options
|
|
178
|
+
* @returns Query options clause as a string
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* // All options
|
|
183
|
+
* const optionsClause = QueryStatementBuilder.BuildQueryOptions({
|
|
184
|
+
* orderBy: 'created_at DESC',
|
|
185
|
+
* limit: 10,
|
|
186
|
+
* offset: 20
|
|
187
|
+
* });
|
|
188
|
+
* // "ORDER BY created_at DESC LIMIT 10 OFFSET 20"
|
|
189
|
+
*
|
|
190
|
+
* // Just ordering
|
|
191
|
+
* const optionsClause = QueryStatementBuilder.BuildQueryOptions({
|
|
192
|
+
* orderBy: 'name ASC'
|
|
193
|
+
* });
|
|
194
|
+
* // "ORDER BY name ASC"
|
|
195
|
+
*
|
|
196
|
+
* // Pagination only
|
|
197
|
+
* const optionsClause = QueryStatementBuilder.BuildQueryOptions({
|
|
198
|
+
* limit: 25,
|
|
199
|
+
* offset: 50
|
|
200
|
+
* });
|
|
201
|
+
* // "LIMIT 25 OFFSET 50"
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
static BuildQueryOptions(options) {
|
|
205
|
+
const queryParts = [];
|
|
206
|
+
if (options === null || options === void 0 ? void 0 : options.orderBy) {
|
|
207
|
+
queryParts.push(`ORDER BY ${options.orderBy}`);
|
|
208
|
+
}
|
|
209
|
+
if (options === null || options === void 0 ? void 0 : options.limit) {
|
|
210
|
+
queryParts.push(`LIMIT ${options.limit}`);
|
|
211
|
+
if (options === null || options === void 0 ? void 0 : options.offset) {
|
|
212
|
+
queryParts.push(`OFFSET ${options.offset}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return queryParts.join(" ");
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PossibleComputedExpressions, PossibleExpressions, expressionClause } from "../index";
|
|
2
|
+
export default interface IExpressionBuilder {
|
|
3
|
+
build(expression: PossibleExpressions | PossibleComputedExpressions): expressionClause;
|
|
4
|
+
validate?(expression: PossibleExpressions | PossibleComputedExpressions): boolean;
|
|
5
|
+
get defaultRequirements(): PossibleExpressions['requirements'];
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=IExpressionBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IExpressionBuilder.d.ts","sourceRoot":"","sources":["../../src/interfaces/IExpressionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEjG,MAAM,CAAC,OAAO,WAAW,kBAAkB;IACvC,KAAK,CAAC,UAAU,EAAE,mBAAmB,GAAG,2BAA2B,GAAG,gBAAgB,CAAC;IACvF,QAAQ,CAAC,CAAC,UAAU,EAAE,mBAAmB,GAAG,2BAA2B,GAAG,OAAO,CAAC;IAClF,IAAI,mBAAmB,IAAI,mBAAmB,CAAC,cAAc,CAAC,CAAC;CAClE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IQueryBuilder.d.ts","sourceRoot":"","sources":["../../src/interfaces/IQueryBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,CAAC,OAAO,WAAW,aAAa;IAClC,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;CAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import SchemaTableBuilder from "../abstract/SchemaTableBuilder.js";
|
|
2
2
|
export default interface AbstractSchemaBuilder {
|
|
3
3
|
createTable(name: string, callback: (table: SchemaTableBuilder) => void): Promise<void>;
|
|
4
|
-
dropTable(name: string): Promise<void>;
|
|
4
|
+
dropTable(name: string, cascade?: boolean): Promise<void>;
|
|
5
5
|
alterTable(oldName: string, callback: (table: SchemaTableBuilder) => void): Promise<void>;
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=ISchemaBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ISchemaBuilder.d.ts","sourceRoot":"","sources":["../../src/interfaces/ISchemaBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,sCAAsC,CAAC;AAEtE,MAAM,CAAC,OAAO,WAAW,qBAAqB;IAC1C,WAAW,CACP,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAC9C,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,SAAS,CACL,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ISchemaBuilder.d.ts","sourceRoot":"","sources":["../../src/interfaces/ISchemaBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,sCAAsC,CAAC;AAEtE,MAAM,CAAC,OAAO,WAAW,qBAAqB;IAC1C,WAAW,CACP,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAC9C,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,SAAS,CACL,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,OAAO,GAClB,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,UAAU,CACN,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAC9C,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB"}
|
|
@@ -3,10 +3,13 @@ declare class Container {
|
|
|
3
3
|
private static _instance;
|
|
4
4
|
private _adapters;
|
|
5
5
|
private _defaultAdapter?;
|
|
6
|
+
logging: boolean;
|
|
6
7
|
private constructor();
|
|
7
8
|
static getInstance(): Container;
|
|
8
9
|
registerAdapter(name: string, adapter: IDatabaseAdapter, isDefault?: boolean): void;
|
|
9
10
|
getAdapter(name?: string): IDatabaseAdapter;
|
|
11
|
+
clear(): void;
|
|
12
|
+
static resetInstance(): void;
|
|
10
13
|
}
|
|
11
14
|
export default Container;
|
|
12
15
|
//# sourceMappingURL=Container.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Container.d.ts","sourceRoot":"","sources":["../../src/runtime/Container.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Container.d.ts","sourceRoot":"","sources":["../../src/runtime/Container.ts"],"names":[],"mappings":"AAEA,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AAEpE,cAAM,SAAS;IACX,OAAO,CAAC,MAAM,CAAC,SAAS,CAAY;IACpC,OAAO,CAAC,SAAS,CAA4C;IAC7D,OAAO,CAAC,eAAe,CAAC,CAAmB;IACpC,OAAO,EAAE,OAAO,CAAS;IAEhC,OAAO;WAEO,WAAW,IAAI,SAAS;IAO/B,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,UAAQ,GAAG,IAAI;IAYjF,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,gBAAgB;IAU3C,KAAK,IAAI,IAAI;WAKN,aAAa,IAAI,IAAI;CAGtC;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import AdapterNotFoundError from "../helpers/Errors/AdapterErrors/AdapterNotFoundError.js";
|
|
2
|
+
import NoDefaultAdapterError from "../helpers/Errors/AdapterErrors/NoDefaultAdapterError.js";
|
|
1
3
|
class Container {
|
|
2
4
|
constructor() {
|
|
3
5
|
this._adapters = new Map();
|
|
6
|
+
this.logging = false;
|
|
4
7
|
}
|
|
5
8
|
static getInstance() {
|
|
6
9
|
if (!Container._instance) {
|
|
@@ -22,12 +25,19 @@ class Container {
|
|
|
22
25
|
if (name) {
|
|
23
26
|
const adapter = this._adapters.get(name);
|
|
24
27
|
if (!adapter)
|
|
25
|
-
throw new
|
|
28
|
+
throw new AdapterNotFoundError(name);
|
|
26
29
|
return adapter;
|
|
27
30
|
}
|
|
28
31
|
if (!this._defaultAdapter)
|
|
29
|
-
throw new
|
|
32
|
+
throw new NoDefaultAdapterError();
|
|
30
33
|
return this._defaultAdapter;
|
|
31
34
|
}
|
|
35
|
+
clear() {
|
|
36
|
+
this._adapters.clear();
|
|
37
|
+
this._defaultAdapter = undefined;
|
|
38
|
+
}
|
|
39
|
+
static resetInstance() {
|
|
40
|
+
Container._instance = new Container();
|
|
41
|
+
}
|
|
32
42
|
}
|
|
33
43
|
export default Container;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TableColumnInfo } from "../types/table.js";
|
|
2
|
+
export default class QueryCache {
|
|
3
|
+
private static _instance?;
|
|
4
|
+
private cachedExistingTables;
|
|
5
|
+
private cachedTableColumnInformation;
|
|
6
|
+
static getInstance(): QueryCache;
|
|
7
|
+
doesTableExist(table: string): boolean;
|
|
8
|
+
addExistingTable(table: string): void;
|
|
9
|
+
getTableColumnInformation(tableName: string): TableColumnInfo[] | undefined;
|
|
10
|
+
setTableColumnInformation(tableName: string, tableColumnInformation: TableColumnInfo[]): Map<string, TableColumnInfo[]>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=QueryCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryCache.d.ts","sourceRoot":"","sources":["../../src/runtime/QueryCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,CAAC,OAAO,OAAO,UAAU;IAC3B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAa;IACtC,OAAO,CAAC,oBAAoB,CAAgB;IAC5C,OAAO,CAAC,4BAA4B,CAA6C;WAEnE,WAAW,IAAI,UAAU;IAQhC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAItC,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAMrC,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,EAAE,GAAG,SAAS;IAI3E,yBAAyB,CAAC,SAAS,EAAE,MAAM,EAAE,sBAAsB,EAAE,eAAe,EAAE;CAGhG"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default class QueryCache {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.cachedExistingTables = [];
|
|
4
|
+
this.cachedTableColumnInformation = new Map();
|
|
5
|
+
}
|
|
6
|
+
static getInstance() {
|
|
7
|
+
if (!this._instance) {
|
|
8
|
+
this._instance = new QueryCache();
|
|
9
|
+
}
|
|
10
|
+
return this._instance;
|
|
11
|
+
}
|
|
12
|
+
doesTableExist(table) {
|
|
13
|
+
return this.cachedExistingTables.includes(table);
|
|
14
|
+
}
|
|
15
|
+
addExistingTable(table) {
|
|
16
|
+
if (!this.doesTableExist(table)) {
|
|
17
|
+
this.cachedExistingTables.push(table);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
getTableColumnInformation(tableName) {
|
|
21
|
+
return this.cachedTableColumnInformation.get(tableName);
|
|
22
|
+
}
|
|
23
|
+
setTableColumnInformation(tableName, tableColumnInformation) {
|
|
24
|
+
return this.cachedTableColumnInformation.set(tableName, tableColumnInformation);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type Model from "../abstract/Model.js";
|
|
2
2
|
import Record from "../base/Record.js";
|
|
3
|
-
import { columnType, QueryWhereCondition,
|
|
3
|
+
import { columnType, QueryWhereCondition, relation, QueryComparisonParameters, QueryIsEqualParameter, TableFactory, QueryLayers } from "../types/index.js";
|
|
4
4
|
export default class Repository<Type extends columnType, ModelType extends Model<Type>> {
|
|
5
5
|
private static _instances;
|
|
6
6
|
private models;
|
|
7
7
|
private manyToManyRelations;
|
|
8
8
|
private Table;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
private customDatabaseAdapter?;
|
|
10
|
+
private tableFactory;
|
|
11
|
+
constructor(tableName: string, ModelClass: ModelType, customDatabaseAdapter?: string, tableFactory?: TableFactory);
|
|
12
|
+
static getInstance<ModelType extends columnType>(ModelClass: new () => Model<ModelType>, tableName: string, customDatabaseAdapter?: string, tableFactory?: TableFactory): Repository<ModelType, Model<ModelType>>;
|
|
13
|
+
static clearInstances(): void;
|
|
11
14
|
private generatePivotTableKeys;
|
|
12
15
|
insertRecordIntoPivotTable(foreignKey: string, modelOfOrigin: ModelType, relation: relation): Promise<void>;
|
|
13
16
|
deleteRecordFromPivotTable(foreignKey: string, modelOfOrigin: ModelType, relation: relation): Promise<void>;
|
|
@@ -16,11 +19,14 @@ export default class Repository<Type extends columnType, ModelType extends Model
|
|
|
16
19
|
syncModel(model: ModelType): void;
|
|
17
20
|
getModel(name: string): ModelType;
|
|
18
21
|
save(attributes: Type): Promise<void>;
|
|
19
|
-
first(
|
|
20
|
-
get(
|
|
21
|
-
all(Model: Model<Type>,
|
|
22
|
+
first(queryLayers: QueryLayers, Model: Model<Type>): Promise<Type | undefined>;
|
|
23
|
+
get(QueryLayers: QueryLayers, Model: Model<Type>): Promise<Type[]>;
|
|
24
|
+
all(Model: Model<Type>, QueryLayers: QueryLayers): Promise<Type[]>;
|
|
22
25
|
update(primaryKey: QueryIsEqualParameter, newAttributes: Partial<Type>): Promise<Record<Type> | undefined>;
|
|
23
26
|
private join;
|
|
24
|
-
|
|
27
|
+
toSql(queryLayers: QueryLayers, Model: Model<Type>): Promise<string>;
|
|
28
|
+
private buildJoinObject;
|
|
29
|
+
mergeQueryWhereConditions(base: QueryWhereCondition, additional: QueryWhereCondition): QueryComparisonParameters[];
|
|
30
|
+
ConvertParamsToArray(params: QueryWhereCondition): QueryComparisonParameters[];
|
|
25
31
|
}
|
|
26
32
|
//# sourceMappingURL=Repository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Repository.d.ts","sourceRoot":"","sources":["../../src/runtime/Repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,yBAAyB,CAAC;AACjD,OAAO,MAAM,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"Repository.d.ts","sourceRoot":"","sources":["../../src/runtime/Repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,yBAAyB,CAAC;AACjD,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAQ,mBAAmB,EAAE,QAAQ,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEpK,MAAM,CAAC,OAAO,OAAO,UAAU,CAAC,IAAI,SAAS,UAAU,EAAE,SAAS,SAAS,KAAK,CAAC,IAAI,CAAC;IAClF,OAAO,CAAC,MAAM,CAAC,UAAU,CAAqE;IAC9F,OAAO,CAAC,MAAM,CAAqC;IACnD,OAAO,CAAC,mBAAmB,CAAoC;IAC/D,OAAO,CAAC,KAAK,CAAO;IACpB,OAAO,CAAC,qBAAqB,CAAC,CAAS;IACvC,OAAO,CAAC,YAAY,CAAe;gBAG/B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,SAAS,EACrB,qBAAqB,CAAC,EAAE,MAAM,EAC9B,YAAY,GAAE,YAA0D;WAS9D,WAAW,CAAC,SAAS,SAAS,UAAU,EAClD,UAAU,EAAE,UAAU,KAAK,CAAC,SAAS,CAAC,EACtC,SAAS,EAAE,MAAM,EACjB,qBAAqB,CAAC,EAAE,MAAM,EAC9B,YAAY,CAAC,EAAE,YAAY,GAC5B,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;WAiB5B,cAAc,IAAI,IAAI;IAIpC,OAAO,CAAC,sBAAsB;IAajB,0BAA0B,CACnC,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,SAAS,EACxB,QAAQ,EAAE,QAAQ,GACnB,OAAO,CAAC,IAAI,CAAC;IAKH,0BAA0B,CACnC,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,SAAS,EACxB,QAAQ,EAAE,QAAQ,GACnB,OAAO,CAAC,IAAI,CAAC;IAMH,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IAaxE,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKpD,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAKjC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAI3B,IAAI,CAAC,UAAU,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrC,KAAK,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;IAY9E,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IASlE,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAIlE,MAAM,CAAC,UAAU,EAAE,qBAAqB,EAAE,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;YAOzG,IAAI;IAaL,KAAK,CACd,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GACnB,OAAO,CAAC,MAAM,CAAC;IAYlB,OAAO,CAAC,eAAe;IA6FhB,yBAAyB,CAAC,IAAI,EAAE,mBAAmB,EAAE,UAAU,EAAE,mBAAmB,GAAG,yBAAyB,EAAE;IAKlH,oBAAoB,CAAC,MAAM,EAAE,mBAAmB,GAAG,yBAAyB,EAAE;CAIxF"}
|