@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
package/dist/base/Table.js
CHANGED
|
@@ -7,25 +7,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import QueryStatementBuilder from "../helpers/QueryStatementBuilder.js";
|
|
10
|
+
import QueryStatementBuilder from "../helpers/QueryBuilders/QueryStatementBuilder.js";
|
|
11
11
|
import { Record, Query } from "../index.js";
|
|
12
12
|
/** Table class for interacting with a database table */
|
|
13
13
|
export default class Table {
|
|
14
14
|
/** Private constructor - use Table.create() */
|
|
15
|
-
constructor(name, customAdapter) {
|
|
15
|
+
constructor(name, customAdapter, queryFactory = (config) => new Query(config), recordFactory = (table, values, adapter) => new Record(table, values, adapter)) {
|
|
16
16
|
this._name = name;
|
|
17
17
|
this._customAdapter = customAdapter;
|
|
18
|
+
this._queryFactory = queryFactory;
|
|
19
|
+
this._recordFactory = recordFactory;
|
|
20
|
+
this._query = this._queryFactory({
|
|
21
|
+
tableName: this._name,
|
|
22
|
+
adapterName: this._customAdapter,
|
|
23
|
+
recordFactory: this._recordFactory
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
get QueryHelperObject() {
|
|
27
|
+
return this._query;
|
|
18
28
|
}
|
|
19
29
|
/** Get raw column information */
|
|
20
|
-
TableColumnInformation() {
|
|
30
|
+
TableColumnInformation(tableName) {
|
|
21
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
return
|
|
32
|
+
return this._query.TableColumnInformation(tableName || this._name);
|
|
23
33
|
});
|
|
24
34
|
}
|
|
25
35
|
/** Get readable, formatted column information */
|
|
26
36
|
ReadableTableColumnInformation() {
|
|
27
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
const columns = yield this.TableColumnInformation();
|
|
38
|
+
const columns = yield this.TableColumnInformation(this._name);
|
|
29
39
|
return columns.map((col) => ({
|
|
30
40
|
name: col.name,
|
|
31
41
|
type: col.type,
|
|
@@ -38,54 +48,50 @@ export default class Table {
|
|
|
38
48
|
Drop() {
|
|
39
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
50
|
const queryStr = `DROP TABLE IF EXISTS "${this._name}";`;
|
|
41
|
-
const query =
|
|
51
|
+
const query = this._queryFactory({
|
|
42
52
|
tableName: this._name,
|
|
43
53
|
query: queryStr,
|
|
44
|
-
adapterName: this._customAdapter
|
|
54
|
+
adapterName: this._customAdapter,
|
|
55
|
+
recordFactory: this._recordFactory
|
|
45
56
|
});
|
|
46
57
|
yield query.Run();
|
|
47
58
|
});
|
|
48
59
|
}
|
|
49
60
|
/** Fetch records with optional filtering, ordering, and pagination */
|
|
50
|
-
Records(
|
|
61
|
+
Records(queryLayers) {
|
|
51
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
orderBy: options === null || options === void 0 ? void 0 : options.orderBy,
|
|
56
|
-
limit: options === null || options === void 0 ? void 0 : options.limit,
|
|
57
|
-
offset: options === null || options === void 0 ? void 0 : options.offset,
|
|
58
|
-
});
|
|
63
|
+
var _a, _b;
|
|
64
|
+
const builder = new QueryStatementBuilder(queryLayers);
|
|
65
|
+
const queryStr = yield builder.build();
|
|
59
66
|
let params = {};
|
|
60
|
-
if ((
|
|
61
|
-
params =
|
|
62
|
-
|
|
67
|
+
if (((_a = queryLayers === null || queryLayers === void 0 ? void 0 : queryLayers.base) === null || _a === void 0 ? void 0 : _a.where) && Object.keys(queryLayers.base.where).length > 0)
|
|
68
|
+
params = queryLayers.base.where;
|
|
69
|
+
if (((_b = queryLayers === null || queryLayers === void 0 ? void 0 : queryLayers.pretty) === null || _b === void 0 ? void 0 : _b.where) && Object.keys(queryLayers.pretty.where).length > 0)
|
|
70
|
+
params = Object.assign(Object.assign({}, params), queryLayers.pretty.where);
|
|
71
|
+
const query = this._queryFactory({
|
|
63
72
|
tableName: this._name,
|
|
64
73
|
query: queryStr,
|
|
65
|
-
parameters: params
|
|
74
|
+
parameters: params,
|
|
75
|
+
recordFactory: this._recordFactory
|
|
66
76
|
});
|
|
67
77
|
const results = yield query.All();
|
|
68
78
|
return results;
|
|
69
79
|
});
|
|
70
80
|
}
|
|
71
81
|
/** Fetch a single record from the table */
|
|
72
|
-
Record(
|
|
82
|
+
Record(queryLayers) {
|
|
73
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
const results = yield this.Records({
|
|
75
|
-
select: options === null || options === void 0 ? void 0 : options.select,
|
|
76
|
-
where: options === null || options === void 0 ? void 0 : options.where,
|
|
77
|
-
orderBy: options === null || options === void 0 ? void 0 : options.orderBy,
|
|
78
|
-
limit: 1
|
|
79
|
-
});
|
|
84
|
+
const results = yield this.Records(Object.assign(Object.assign({}, queryLayers), { final: Object.assign(Object.assign({}, queryLayers === null || queryLayers === void 0 ? void 0 : queryLayers.final), { limit: 1 }) }));
|
|
80
85
|
return results[0];
|
|
81
86
|
});
|
|
82
87
|
}
|
|
83
88
|
/** Get the total count of records */
|
|
84
89
|
RecordsCount() {
|
|
85
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
const query =
|
|
91
|
+
const query = this._queryFactory({
|
|
87
92
|
tableName: this._name,
|
|
88
|
-
query: `SELECT COUNT(*) as count FROM "${this._name}"
|
|
93
|
+
query: `SELECT COUNT(*) as count FROM "${this._name}"`,
|
|
94
|
+
recordFactory: this._recordFactory
|
|
89
95
|
});
|
|
90
96
|
const count = yield query.Count();
|
|
91
97
|
return count || 0;
|
|
@@ -93,9 +99,10 @@ export default class Table {
|
|
|
93
99
|
}
|
|
94
100
|
exists() {
|
|
95
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
const query =
|
|
102
|
+
const query = this._queryFactory({
|
|
97
103
|
tableName: this._name,
|
|
98
|
-
adapterName: this._customAdapter
|
|
104
|
+
adapterName: this._customAdapter,
|
|
105
|
+
recordFactory: this._recordFactory
|
|
99
106
|
});
|
|
100
107
|
return yield query.DoesTableExist();
|
|
101
108
|
});
|
|
@@ -103,27 +110,39 @@ export default class Table {
|
|
|
103
110
|
/** Insert a record into the table */
|
|
104
111
|
Insert(values) {
|
|
105
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
const record =
|
|
113
|
+
const record = this._recordFactory(this._name, values, this._customAdapter);
|
|
107
114
|
yield record.Insert();
|
|
108
115
|
return record;
|
|
109
116
|
});
|
|
110
117
|
}
|
|
111
118
|
/** Perform JOIN operations with other tables */
|
|
112
|
-
Join(
|
|
119
|
+
Join(queryLayers) {
|
|
113
120
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
|
|
121
|
+
var _a, _b;
|
|
122
|
+
if (queryLayers.base.joins === undefined || (Array.isArray(queryLayers.base.joins) && queryLayers.base.joins.length === 0)) {
|
|
123
|
+
throw new Error("No joins defined for the Join operation.");
|
|
124
|
+
}
|
|
125
|
+
const joinedTables = queryLayers.base.joins.map(j => j.fromTable);
|
|
126
|
+
const tableColumnCache = new Map();
|
|
127
|
+
const columnInfo = yield this._query.TableColumnInformation(this._name);
|
|
128
|
+
tableColumnCache.set(this._name, columnInfo);
|
|
129
|
+
for (const tableName of joinedTables) {
|
|
130
|
+
const columnInfo = yield this._query.TableColumnInformation(tableName);
|
|
131
|
+
tableColumnCache.set(tableName, columnInfo);
|
|
132
|
+
}
|
|
133
|
+
const builder = new QueryStatementBuilder(queryLayers, tableColumnCache);
|
|
134
|
+
const queryString = yield builder.build();
|
|
115
135
|
let params = {};
|
|
116
|
-
if (
|
|
117
|
-
params =
|
|
118
|
-
|
|
136
|
+
if ((_a = queryLayers === null || queryLayers === void 0 ? void 0 : queryLayers.base) === null || _a === void 0 ? void 0 : _a.where)
|
|
137
|
+
params = this.QueryHelperObject.ConvertParamsToObject(queryLayers.base.where);
|
|
138
|
+
if ((_b = queryLayers === null || queryLayers === void 0 ? void 0 : queryLayers.pretty) === null || _b === void 0 ? void 0 : _b.where)
|
|
139
|
+
params = Object.assign(Object.assign({}, params), this.QueryHelperObject.ConvertParamsToObject(queryLayers.pretty.where));
|
|
140
|
+
const query = this._queryFactory({
|
|
119
141
|
tableName: this._name,
|
|
120
142
|
query: queryString,
|
|
121
|
-
parameters: params
|
|
143
|
+
parameters: params,
|
|
144
|
+
recordFactory: this._recordFactory
|
|
122
145
|
});
|
|
123
|
-
const joinedTables = Array.isArray(Joins) ? Joins.map(j => j.fromTable) : [Joins.fromTable];
|
|
124
|
-
if (options) {
|
|
125
|
-
options.select = joinedTables.map(table => `${table}.*`).join(', ');
|
|
126
|
-
}
|
|
127
146
|
const records = yield query.All();
|
|
128
147
|
const splitTables = yield this.splitJoinValues(records, joinedTables);
|
|
129
148
|
return splitTables;
|
|
@@ -132,13 +151,11 @@ export default class Table {
|
|
|
132
151
|
splitJoinValues(records, joinedTables) {
|
|
133
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
134
153
|
return records.map(record => {
|
|
154
|
+
var _a;
|
|
135
155
|
if (!record.values)
|
|
136
156
|
return record;
|
|
137
157
|
const mainTableData = {};
|
|
138
158
|
const joinedTableData = {};
|
|
139
|
-
for (const tableName of joinedTables) {
|
|
140
|
-
joinedTableData[tableName] = {};
|
|
141
|
-
}
|
|
142
159
|
for (const [aliasedKey, value] of Object.entries(record.values)) {
|
|
143
160
|
if (aliasedKey.includes('__')) {
|
|
144
161
|
const [tableName, columnName] = aliasedKey.split('__');
|
|
@@ -146,6 +163,7 @@ export default class Table {
|
|
|
146
163
|
mainTableData[columnName] = value;
|
|
147
164
|
}
|
|
148
165
|
else if (joinedTables.includes(tableName)) {
|
|
166
|
+
(_a = joinedTableData[tableName]) !== null && _a !== void 0 ? _a : (joinedTableData[tableName] = {});
|
|
149
167
|
joinedTableData[tableName][columnName] = value;
|
|
150
168
|
}
|
|
151
169
|
}
|
|
@@ -153,10 +171,32 @@ export default class Table {
|
|
|
153
171
|
mainTableData[aliasedKey] = value;
|
|
154
172
|
}
|
|
155
173
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
174
|
+
const filteredJoinedData = Object.fromEntries(
|
|
175
|
+
// eslint-disable-next-line no-unused-vars
|
|
176
|
+
Object.entries(joinedTableData).filter(([_, data]) => Object.keys(data).length > 0));
|
|
177
|
+
const combinedData = Object.assign(Object.assign({}, mainTableData), filteredJoinedData);
|
|
178
|
+
return this._recordFactory(this._name, combinedData, this._customAdapter);
|
|
159
179
|
});
|
|
160
180
|
});
|
|
161
181
|
}
|
|
182
|
+
toSql(queryLayers) {
|
|
183
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
if (queryLayers.base.joins && queryLayers.base.joins.length > 0) {
|
|
185
|
+
const joinedTables = queryLayers.base.joins.map(j => j.fromTable);
|
|
186
|
+
const tableColumnCache = new Map();
|
|
187
|
+
const columnInfo = yield this._query.TableColumnInformation(this._name);
|
|
188
|
+
tableColumnCache.set(this._name, columnInfo);
|
|
189
|
+
for (const tableName of joinedTables) {
|
|
190
|
+
const columnInfo = yield this._query.TableColumnInformation(tableName);
|
|
191
|
+
tableColumnCache.set(tableName, columnInfo);
|
|
192
|
+
}
|
|
193
|
+
const builder = new QueryStatementBuilder(queryLayers, tableColumnCache);
|
|
194
|
+
return yield builder.build();
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
const builder = new QueryStatementBuilder(queryLayers);
|
|
198
|
+
return yield builder.build();
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
162
202
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AdapterNotFoundError.d.ts","sourceRoot":"","sources":["../../../../src/helpers/Errors/AdapterErrors/AdapterNotFoundError.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,KAAK;gBACvC,WAAW,EAAE,MAAM;CAIlC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionFailedError.d.ts","sourceRoot":"","sources":["../../../../src/helpers/Errors/AdapterErrors/ConnectionFailedError.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,KAAK;gBACxC,OAAO,EAAE,MAAM;CAI9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NoDefaultAdapterError.d.ts","sourceRoot":"","sources":["../../../../src/helpers/Errors/AdapterErrors/NoDefaultAdapterError.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,KAAK;;CAKvD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InvalidExpressionParametersError.d.ts","sourceRoot":"","sources":["../../../../src/helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,gCAAiC,SAAQ,KAAK;gBACnD,OAAO,EAAE,MAAM;CAI9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnknownExpressionTypeError.d.ts","sourceRoot":"","sources":["../../../../src/helpers/Errors/ExpressionErrors/UnknownExpressionTypeError.ts"],"names":[],"mappings":"AAAA,qBAAa,0BAA2B,SAAQ,KAAK;gBACrC,IAAI,EAAE,MAAM;CAI3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnsupportedQueryPhaseError.d.ts","sourceRoot":"","sources":["../../../../src/helpers/Errors/ExpressionErrors/UnsupportedQueryPhaseError.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,0BAA2B,SAAQ,KAAK;gBAC7C,KAAK,CAAC,EAAE,MAAM;CAI7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnexpectedEmptyQueryError.d.ts","sourceRoot":"","sources":["../../../../src/helpers/Errors/QueryErrors/UnexpectedEmptyQueryError.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,yBAA0B,SAAQ,KAAK;;CAK3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnknownTableError.d.ts","sourceRoot":"","sources":["../../../../src/helpers/Errors/TableErrors/UnknownTableError.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,KAAK;gBACpC,SAAS,EAAE,MAAM;CAIhC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=BaseDeleteQueryBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseDeleteQueryBuilder.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/BaseQueryBuilders/BaseDeleteQueryBuilder.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=BaseInsertQueryBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseInsertQueryBuilder.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/BaseQueryBuilders/BaseInsertQueryBuilder.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import IQueryBuilder from "../../../interfaces/IQueryBuilder.js";
|
|
3
|
+
// export default class BaseInsertQueryBuilder implements IQueryBuilder {
|
|
4
|
+
// private tableName: string;
|
|
5
|
+
// constructor(tableName: string) {
|
|
6
|
+
// this.tableName = tableName;
|
|
7
|
+
// }
|
|
8
|
+
// async build(): Promise<string> {
|
|
9
|
+
// return `INSERT INTO "${this.tableName}"`;
|
|
10
|
+
// }
|
|
11
|
+
// }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { QueryContext } from "../../../index";
|
|
2
|
+
import IQueryBuilder from "../../../interfaces/IQueryBuilder.js";
|
|
3
|
+
export default class BaseSelectQueryBuilder implements IQueryBuilder {
|
|
4
|
+
private tableName;
|
|
5
|
+
private select;
|
|
6
|
+
private joinsSelect?;
|
|
7
|
+
private expressionsSelect?;
|
|
8
|
+
constructor(tableName: string, select: string[], joinsSelect?: string[], expressionsSelect?: string[]);
|
|
9
|
+
build(): Promise<QueryContext>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=BaseSelectQueryBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseSelectQueryBuilder.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,aAAa,MAAM,mCAAmC,CAAC;AAE9D,MAAM,CAAC,OAAO,OAAO,sBAAuB,YAAW,aAAa;IAChE,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,WAAW,CAAC,CAAW;IAC/B,OAAO,CAAC,iBAAiB,CAAC,CAAW;gBAEzB,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,EAAE,iBAAiB,CAAC,EAAE,MAAM,EAAE;IAO/F,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC;CAQvC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
export default class BaseSelectQueryBuilder {
|
|
11
|
+
constructor(tableName, select, joinsSelect, expressionsSelect) {
|
|
12
|
+
this.tableName = tableName;
|
|
13
|
+
this.select = select;
|
|
14
|
+
this.joinsSelect = joinsSelect;
|
|
15
|
+
this.expressionsSelect = expressionsSelect;
|
|
16
|
+
}
|
|
17
|
+
build() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
return {
|
|
20
|
+
select: this.select,
|
|
21
|
+
joinsSelect: this.joinsSelect,
|
|
22
|
+
from: this.tableName,
|
|
23
|
+
expressionSelect: this.expressionsSelect,
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=BaseUpdateQueryBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseUpdateQueryBuilder.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/BaseQueryBuilders/BaseUpdateQueryBuilder.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { expressionClause, JsonAggregateQueryExpression } from "../../../index.js";
|
|
2
|
+
import IExpressionBuilder from "../../../interfaces/IExpressionBuilder.js";
|
|
3
|
+
export default class JsonAggregateExpression implements IExpressionBuilder {
|
|
4
|
+
build(expression: JsonAggregateQueryExpression): expressionClause;
|
|
5
|
+
private buildJsonBuildObject;
|
|
6
|
+
validate(expression: JsonAggregateQueryExpression): boolean;
|
|
7
|
+
get defaultRequirements(): JsonAggregateQueryExpression['requirements'];
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=JsonAggregateExpression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonAggregateExpression.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,4BAA4B,EAAwE,MAAM,gBAAgB,CAAC;AACtJ,OAAO,kBAAkB,MAAM,wCAAwC,CAAC;AAUxE,MAAM,CAAC,OAAO,OAAO,uBAAwB,YAAW,kBAAkB;IACtE,KAAK,CAAC,UAAU,EAAE,4BAA4B,GAAG,gBAAgB;IA8BjE,OAAO,CAAC,oBAAoB;IAqE5B,QAAQ,CAAC,UAAU,EAAE,4BAA4B,GAAG,OAAO;IAa3D,IAAI,mBAAmB,IAAI,4BAA4B,CAAC,cAAc,CAAC,CAOtE;CACJ"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import InvalidExpressionParametersError from "../../../helpers/Errors/ExpressionErrors/InvalidExpressionParametersError.js";
|
|
2
|
+
import { QueryEvaluationPhase } from "../../../index.js";
|
|
3
|
+
import QueryExpressionBuilder from "../QueryExpressionBuilder.js";
|
|
4
|
+
import QueryStatementBuilder from "../QueryStatementBuilder.js";
|
|
5
|
+
export default class JsonAggregateExpression {
|
|
6
|
+
build(expression) {
|
|
7
|
+
if (!this.validate(expression)) {
|
|
8
|
+
throw new InvalidExpressionParametersError("Invalid JSON aggregate expression parameters.");
|
|
9
|
+
}
|
|
10
|
+
const jsonBuildObjects = this.buildJsonBuildObject(expression);
|
|
11
|
+
const baseExpressionClause = `JSON_AGG(
|
|
12
|
+
${jsonBuildObjects.sql}
|
|
13
|
+
) AS ${expression.parameters.alias}`;
|
|
14
|
+
const groupByClause = expression.parameters.groupByColumns.length > 0
|
|
15
|
+
? expression.parameters.groupByColumns
|
|
16
|
+
.map(col => col.includes(".") ? `"${col.replace(".", "__")}"` : `"${col}"`)
|
|
17
|
+
.join(", ")
|
|
18
|
+
: undefined;
|
|
19
|
+
return {
|
|
20
|
+
baseExpressionClause,
|
|
21
|
+
phase: expression.requirements.phase,
|
|
22
|
+
requiresWrapping: expression.requirements.requiresSelectWrapping || false,
|
|
23
|
+
groupByClause,
|
|
24
|
+
whereClause: jsonBuildObjects.whereClause,
|
|
25
|
+
valueClauseKeywords: jsonBuildObjects.valueClauseKeywords,
|
|
26
|
+
havingClause: expression.parameters.having
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
buildJsonBuildObject(expression) {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
const columnPart = expression.parameters.columns
|
|
32
|
+
.map(col => `'${col}', "${expression.parameters.table}_${col}"`)
|
|
33
|
+
.join(",\n ");
|
|
34
|
+
const computedPart = ((_a = expression.parameters.computed) === null || _a === void 0 ? void 0 : _a.length)
|
|
35
|
+
? expression.parameters.computed
|
|
36
|
+
.map(comp => {
|
|
37
|
+
var _a;
|
|
38
|
+
const valueClauseKeywords = [`${comp.parameters.alias}_lat`, `${comp.parameters.alias}_lon`];
|
|
39
|
+
const expr = {
|
|
40
|
+
type: comp.type,
|
|
41
|
+
parameters: Object.assign(Object.assign({}, comp.parameters), { valueClauseKeywords: comp.type === 'spatialDistance' ? valueClauseKeywords : comp.parameters.valueClauseKeywords, isComputed: true }),
|
|
42
|
+
requirements: QueryExpressionBuilder.getExpressionDefaultRequirements(comp.type)
|
|
43
|
+
};
|
|
44
|
+
const builder = QueryExpressionBuilder.buildExpressionsPart([expr])[0];
|
|
45
|
+
return {
|
|
46
|
+
sql: `'${comp.parameters.alias}', ${(_a = builder.baseExpressionClause) === null || _a === void 0 ? void 0 : _a.split(" AS ")[0]}`,
|
|
47
|
+
whereClause: builder.whereClause,
|
|
48
|
+
valueClauseKeywords: builder.valueClauseKeywords
|
|
49
|
+
};
|
|
50
|
+
}) : [];
|
|
51
|
+
const computedSqlPart = computedPart.length
|
|
52
|
+
? computedPart.map(c => c.sql).join(",\n ")
|
|
53
|
+
: "";
|
|
54
|
+
const whereClauses = computedPart
|
|
55
|
+
.flatMap(c => c.whereClause ? QueryStatementBuilder.normalizeQueryConditions(c.whereClause) : []);
|
|
56
|
+
const valueClauseKeywords = computedPart
|
|
57
|
+
.flatMap(c => c.valueClauseKeywords || []);
|
|
58
|
+
const nestedPart = ((_b = expression.parameters.nested) === null || _b === void 0 ? void 0 : _b.length)
|
|
59
|
+
? expression.parameters.nested
|
|
60
|
+
.map(n => {
|
|
61
|
+
return `'${n.alias}', ${this.buildJsonBuildObject({
|
|
62
|
+
type: 'jsonAggregate',
|
|
63
|
+
parameters: {
|
|
64
|
+
table: n.table,
|
|
65
|
+
alias: n.alias,
|
|
66
|
+
columns: n.columns,
|
|
67
|
+
computed: n.computed,
|
|
68
|
+
nested: n.nested,
|
|
69
|
+
groupByColumns: []
|
|
70
|
+
},
|
|
71
|
+
requirements: this.defaultRequirements
|
|
72
|
+
}).sql}`;
|
|
73
|
+
})
|
|
74
|
+
.join(",\n ")
|
|
75
|
+
: "";
|
|
76
|
+
const parts = [columnPart, computedSqlPart, nestedPart].filter(Boolean).join(",\n ");
|
|
77
|
+
return {
|
|
78
|
+
sql: `JSON_BUILD_OBJECT(
|
|
79
|
+
${parts}
|
|
80
|
+
)`,
|
|
81
|
+
whereClause: whereClauses,
|
|
82
|
+
valueClauseKeywords: valueClauseKeywords
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
validate(expression) {
|
|
86
|
+
if (expression.type !== 'jsonAggregate') {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
return (Array.isArray(expression.parameters.columns) &&
|
|
90
|
+
typeof expression.parameters.table === 'string' &&
|
|
91
|
+
Array.isArray(expression.parameters.groupByColumns) &&
|
|
92
|
+
typeof expression.parameters.alias === 'string');
|
|
93
|
+
}
|
|
94
|
+
get defaultRequirements() {
|
|
95
|
+
return {
|
|
96
|
+
phase: QueryEvaluationPhase.PROJECTION,
|
|
97
|
+
cardinality: 'row',
|
|
98
|
+
requiresAlias: true,
|
|
99
|
+
requiresSelectWrapping: true
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import IExpressionBuilder from "../../../interfaces/IExpressionBuilder.js";
|
|
2
|
+
import { expressionClause, SpatialQueryExpression } from "../../../types/index.js";
|
|
3
|
+
export default class SpatialDistanceExpression implements IExpressionBuilder {
|
|
4
|
+
build(expression: SpatialQueryExpression): expressionClause;
|
|
5
|
+
validate(expression: SpatialQueryExpression): boolean;
|
|
6
|
+
get defaultRequirements(): SpatialQueryExpression['requirements'];
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=SpatialDistanceExpression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpatialDistanceExpression.d.ts","sourceRoot":"","sources":["../../../../src/helpers/QueryBuilders/ExpressionBuilders/SpatialDistanceExpression.ts"],"names":[],"mappings":"AACA,OAAO,kBAAkB,MAAM,wCAAwC,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAwB,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAGtG,MAAM,CAAC,OAAO,OAAO,yBAA0B,YAAW,kBAAkB;IACxE,KAAK,CAAC,UAAU,EAAE,sBAAsB,GAAG,gBAAgB;IAkD3D,QAAQ,CAAC,UAAU,EAAE,sBAAsB,GAAG,OAAO;IAcrD,IAAI,mBAAmB,IAAI,sBAAsB,CAAC,cAAc,CAAC,CAOhE;CACJ"}
|