@iamkirbki/database-handler-core 4.4.3 → 4.4.5
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.js +18 -39
- package/dist/abstract/Model.d.ts.map +1 -1
- package/dist/abstract/Model.js +100 -98
- package/dist/abstract/SchemaTableBuilder.js +4 -1
- package/dist/abstract/model/ModelRelation.d.ts +4 -4
- package/dist/abstract/model/ModelRelation.d.ts.map +1 -1
- package/dist/abstract/model/ModelRelation.js +47 -49
- package/dist/base/Query.js +56 -79
- package/dist/base/Record.js +75 -90
- package/dist/base/Table.d.ts.map +1 -1
- package/dist/base/Table.js +130 -153
- package/dist/helpers/QueryBuilders/BaseQueryBuilders/BaseSelectQueryBuilder.js +7 -18
- package/dist/helpers/QueryBuilders/ExpressionBuilders/JsonAggregateExpression.js +5 -1
- package/dist/helpers/QueryBuilders/QueryDecorators/ExpressionDecorator.js +7 -18
- package/dist/helpers/QueryBuilders/QueryDecorators/GroupByDecorator.js +8 -19
- package/dist/helpers/QueryBuilders/QueryDecorators/JoinDecorator.js +26 -39
- package/dist/helpers/QueryBuilders/QueryDecorators/LimitDecorator.js +9 -20
- package/dist/helpers/QueryBuilders/QueryDecorators/OrderByDecorator.js +8 -19
- package/dist/helpers/QueryBuilders/QueryDecorators/WhereDecorator.js +9 -20
- package/dist/helpers/QueryBuilders/QueryStatementBuilder.js +87 -101
- package/dist/runtime/Repository.d.ts +1 -1
- package/dist/runtime/Repository.d.ts.map +1 -1
- package/dist/runtime/Repository.js +98 -102
- package/dist/types/model.d.ts +3 -0
- package/dist/types/model.d.ts.map +1 -1
- package/dist/types/table.d.ts +1 -0
- package/dist/types/table.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/base/Table.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
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
1
|
import QueryStatementBuilder from "../helpers/QueryBuilders/QueryStatementBuilder.js";
|
|
11
2
|
import { Record, Query } from "../index.js";
|
|
12
3
|
/** Table class for interacting with a database table */
|
|
@@ -27,176 +18,162 @@ export default class Table {
|
|
|
27
18
|
return this._query;
|
|
28
19
|
}
|
|
29
20
|
/** Get raw column information */
|
|
30
|
-
TableColumnInformation(tableName) {
|
|
31
|
-
return
|
|
32
|
-
return this._query.TableColumnInformation(tableName || this._name);
|
|
33
|
-
});
|
|
21
|
+
async TableColumnInformation(tableName) {
|
|
22
|
+
return this._query.TableColumnInformation(tableName || this._name);
|
|
34
23
|
}
|
|
35
24
|
/** Get readable, formatted column information */
|
|
36
|
-
ReadableTableColumnInformation() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}));
|
|
46
|
-
});
|
|
25
|
+
async ReadableTableColumnInformation() {
|
|
26
|
+
const columns = await this.TableColumnInformation(this._name);
|
|
27
|
+
return columns.map((col) => ({
|
|
28
|
+
name: col.name,
|
|
29
|
+
type: col.type,
|
|
30
|
+
nullable: col.notnull === 0,
|
|
31
|
+
isPrimaryKey: col.pk === 1,
|
|
32
|
+
defaultValue: col.dflt_value,
|
|
33
|
+
}));
|
|
47
34
|
}
|
|
48
|
-
Drop() {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
recordFactory: this._recordFactory
|
|
56
|
-
});
|
|
57
|
-
yield query.Run();
|
|
35
|
+
async Drop() {
|
|
36
|
+
const queryStr = `DROP TABLE IF EXISTS "${this._name}";`;
|
|
37
|
+
const query = this._queryFactory({
|
|
38
|
+
tableName: this._name,
|
|
39
|
+
query: queryStr,
|
|
40
|
+
adapterName: this._customAdapter,
|
|
41
|
+
recordFactory: this._recordFactory
|
|
58
42
|
});
|
|
43
|
+
await query.Run();
|
|
59
44
|
}
|
|
60
45
|
/** Fetch records with optional filtering, ordering, and pagination */
|
|
61
|
-
Records(queryLayers) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
recordFactory: this._recordFactory
|
|
76
|
-
});
|
|
77
|
-
const results = yield query.All();
|
|
78
|
-
return results;
|
|
46
|
+
async Records(queryLayers) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const builder = new QueryStatementBuilder(queryLayers);
|
|
49
|
+
const queryStr = await builder.build();
|
|
50
|
+
let params = {};
|
|
51
|
+
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)
|
|
52
|
+
params = queryLayers.base.where;
|
|
53
|
+
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)
|
|
54
|
+
params = { ...params, ...queryLayers.pretty.where };
|
|
55
|
+
const query = this._queryFactory({
|
|
56
|
+
tableName: this._name,
|
|
57
|
+
query: queryStr,
|
|
58
|
+
parameters: params,
|
|
59
|
+
recordFactory: this._recordFactory
|
|
79
60
|
});
|
|
61
|
+
const results = await query.All();
|
|
62
|
+
return results;
|
|
80
63
|
}
|
|
81
64
|
/** Fetch a single record from the table */
|
|
82
|
-
Record(queryLayers) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
65
|
+
async Record(queryLayers) {
|
|
66
|
+
const results = await this.Records({
|
|
67
|
+
...queryLayers,
|
|
68
|
+
final: {
|
|
69
|
+
...queryLayers === null || queryLayers === void 0 ? void 0 : queryLayers.final,
|
|
70
|
+
limit: 1,
|
|
71
|
+
},
|
|
86
72
|
});
|
|
73
|
+
return results[0];
|
|
87
74
|
}
|
|
88
75
|
/** Get the total count of records */
|
|
89
|
-
RecordsCount() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
recordFactory: this._recordFactory
|
|
95
|
-
});
|
|
96
|
-
const count = yield query.Count();
|
|
97
|
-
return count || 0;
|
|
76
|
+
async RecordsCount() {
|
|
77
|
+
const query = this._queryFactory({
|
|
78
|
+
tableName: this._name,
|
|
79
|
+
query: `SELECT COUNT(*) as count FROM "${this._name}"`,
|
|
80
|
+
recordFactory: this._recordFactory
|
|
98
81
|
});
|
|
82
|
+
const count = await query.Count();
|
|
83
|
+
return count || 0;
|
|
99
84
|
}
|
|
100
|
-
exists() {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
recordFactory: this._recordFactory
|
|
106
|
-
});
|
|
107
|
-
return yield query.DoesTableExist();
|
|
85
|
+
async exists() {
|
|
86
|
+
const query = this._queryFactory({
|
|
87
|
+
tableName: this._name,
|
|
88
|
+
adapterName: this._customAdapter,
|
|
89
|
+
recordFactory: this._recordFactory
|
|
108
90
|
});
|
|
91
|
+
return await query.DoesTableExist();
|
|
109
92
|
}
|
|
110
93
|
/** Insert a record into the table */
|
|
111
|
-
Insert(values) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return record;
|
|
116
|
-
});
|
|
94
|
+
async Insert(values) {
|
|
95
|
+
const record = this._recordFactory(this._name, values, this._customAdapter);
|
|
96
|
+
await record.Insert();
|
|
97
|
+
return record;
|
|
117
98
|
}
|
|
118
99
|
/** Perform JOIN operations with other tables */
|
|
119
|
-
Join(queryLayers) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
recordFactory: this._recordFactory
|
|
145
|
-
});
|
|
146
|
-
const records = yield query.All();
|
|
147
|
-
const splitTables = yield this.splitJoinValues(records, joinedTables);
|
|
148
|
-
return splitTables;
|
|
100
|
+
async Join(queryLayers) {
|
|
101
|
+
var _a, _b;
|
|
102
|
+
if (queryLayers.base.joins === undefined || (Array.isArray(queryLayers.base.joins) && queryLayers.base.joins.length === 0)) {
|
|
103
|
+
throw new Error("No joins defined for the Join operation.");
|
|
104
|
+
}
|
|
105
|
+
const joinedTables = queryLayers.base.joins.map(j => j.fromTable);
|
|
106
|
+
const tableColumnCache = new Map();
|
|
107
|
+
const columnInfo = await this._query.TableColumnInformation(this._name);
|
|
108
|
+
tableColumnCache.set(this._name, columnInfo);
|
|
109
|
+
for (const tableName of joinedTables) {
|
|
110
|
+
const columnInfo = await this._query.TableColumnInformation(tableName);
|
|
111
|
+
tableColumnCache.set(tableName, columnInfo);
|
|
112
|
+
}
|
|
113
|
+
const builder = new QueryStatementBuilder(queryLayers, tableColumnCache);
|
|
114
|
+
const queryString = await builder.build();
|
|
115
|
+
let params = {};
|
|
116
|
+
if ((_a = queryLayers === null || queryLayers === void 0 ? void 0 : queryLayers.base) === null || _a === void 0 ? void 0 : _a.where)
|
|
117
|
+
params = this.QueryHelperObject.ConvertParamsToObject(queryLayers.base.where);
|
|
118
|
+
if ((_b = queryLayers === null || queryLayers === void 0 ? void 0 : queryLayers.pretty) === null || _b === void 0 ? void 0 : _b.where)
|
|
119
|
+
params = { ...params, ...this.QueryHelperObject.ConvertParamsToObject(queryLayers.pretty.where) };
|
|
120
|
+
const query = this._queryFactory({
|
|
121
|
+
tableName: this._name,
|
|
122
|
+
query: queryString,
|
|
123
|
+
parameters: params,
|
|
124
|
+
recordFactory: this._recordFactory
|
|
149
125
|
});
|
|
126
|
+
const records = await query.All();
|
|
127
|
+
const splitTables = await this.splitJoinValues(records, joinedTables, queryLayers.base.joins);
|
|
128
|
+
return splitTables;
|
|
150
129
|
}
|
|
151
|
-
splitJoinValues(records, joinedTables) {
|
|
152
|
-
return
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
mainTableData[columnName] = value;
|
|
164
|
-
}
|
|
165
|
-
else if (joinedTables.includes(tableName)) {
|
|
166
|
-
(_a = joinedTableData[tableName]) !== null && _a !== void 0 ? _a : (joinedTableData[tableName] = {});
|
|
167
|
-
joinedTableData[tableName][columnName] = value;
|
|
168
|
-
}
|
|
130
|
+
async splitJoinValues(records, joinedTables, joins) {
|
|
131
|
+
return records.map(record => {
|
|
132
|
+
var _a;
|
|
133
|
+
if (!record.values)
|
|
134
|
+
return record;
|
|
135
|
+
const mainTableData = {};
|
|
136
|
+
const joinedTableData = {};
|
|
137
|
+
for (const [aliasedKey, value] of Object.entries(record.values)) {
|
|
138
|
+
if (aliasedKey.includes('__')) {
|
|
139
|
+
const [tableName, columnName] = aliasedKey.split('__');
|
|
140
|
+
if (tableName === this._name) {
|
|
141
|
+
mainTableData[columnName] = value;
|
|
169
142
|
}
|
|
170
|
-
else {
|
|
171
|
-
|
|
143
|
+
else if (joinedTables.includes(tableName)) {
|
|
144
|
+
const currentJoin = joins.find(j => j.fromTable === tableName);
|
|
145
|
+
const aliasedTableName = (currentJoin === null || currentJoin === void 0 ? void 0 : currentJoin.name) || tableName;
|
|
146
|
+
(_a = joinedTableData[aliasedTableName]) !== null && _a !== void 0 ? _a : (joinedTableData[aliasedTableName] = {});
|
|
147
|
+
joinedTableData[aliasedTableName][columnName] = value;
|
|
172
148
|
}
|
|
173
149
|
}
|
|
174
|
-
|
|
175
|
-
|
|
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);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
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);
|
|
150
|
+
else {
|
|
151
|
+
mainTableData[aliasedKey] = value;
|
|
192
152
|
}
|
|
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
153
|
}
|
|
154
|
+
const filteredJoinedData = Object.fromEntries(
|
|
155
|
+
// eslint-disable-next-line no-unused-vars
|
|
156
|
+
Object.entries(joinedTableData).filter(([_, data]) => Object.keys(data).length > 0));
|
|
157
|
+
const combinedData = { ...mainTableData, ...filteredJoinedData };
|
|
158
|
+
return this._recordFactory(this._name, combinedData, this._customAdapter);
|
|
200
159
|
});
|
|
201
160
|
}
|
|
161
|
+
async toSql(queryLayers) {
|
|
162
|
+
if (queryLayers.base.joins && queryLayers.base.joins.length > 0) {
|
|
163
|
+
const joinedTables = queryLayers.base.joins.map(j => j.fromTable);
|
|
164
|
+
const tableColumnCache = new Map();
|
|
165
|
+
const columnInfo = await this._query.TableColumnInformation(this._name);
|
|
166
|
+
tableColumnCache.set(this._name, columnInfo);
|
|
167
|
+
for (const tableName of joinedTables) {
|
|
168
|
+
const columnInfo = await this._query.TableColumnInformation(tableName);
|
|
169
|
+
tableColumnCache.set(tableName, columnInfo);
|
|
170
|
+
}
|
|
171
|
+
const builder = new QueryStatementBuilder(queryLayers, tableColumnCache);
|
|
172
|
+
return await builder.build();
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
const builder = new QueryStatementBuilder(queryLayers);
|
|
176
|
+
return await builder.build();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
202
179
|
}
|
|
@@ -1,12 +1,3 @@
|
|
|
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
1
|
export default class BaseSelectQueryBuilder {
|
|
11
2
|
constructor(tableName, select, joinsSelect, expressionsSelect) {
|
|
12
3
|
this.tableName = tableName;
|
|
@@ -14,14 +5,12 @@ export default class BaseSelectQueryBuilder {
|
|
|
14
5
|
this.joinsSelect = joinsSelect;
|
|
15
6
|
this.expressionsSelect = expressionsSelect;
|
|
16
7
|
}
|
|
17
|
-
build() {
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
});
|
|
8
|
+
async build() {
|
|
9
|
+
return {
|
|
10
|
+
select: this.select,
|
|
11
|
+
joinsSelect: this.joinsSelect,
|
|
12
|
+
from: this.tableName,
|
|
13
|
+
expressionSelect: this.expressionsSelect,
|
|
14
|
+
};
|
|
26
15
|
}
|
|
27
16
|
}
|
|
@@ -38,7 +38,11 @@ export default class JsonAggregateExpression {
|
|
|
38
38
|
const valueClauseKeywords = [`${comp.parameters.alias}_lat`, `${comp.parameters.alias}_lon`];
|
|
39
39
|
const expr = {
|
|
40
40
|
type: comp.type,
|
|
41
|
-
parameters:
|
|
41
|
+
parameters: {
|
|
42
|
+
...comp.parameters,
|
|
43
|
+
valueClauseKeywords: comp.type === 'spatialDistance' ? valueClauseKeywords : comp.parameters.valueClauseKeywords,
|
|
44
|
+
isComputed: true
|
|
45
|
+
},
|
|
42
46
|
requirements: QueryExpressionBuilder.getExpressionDefaultRequirements(comp.type)
|
|
43
47
|
};
|
|
44
48
|
const builder = QueryExpressionBuilder.buildExpressionsPart([expr])[0];
|
|
@@ -1,12 +1,3 @@
|
|
|
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
1
|
import QueryDecorator from "./QueryDecorator.js";
|
|
11
2
|
import QueryStatementBuilder from "../QueryStatementBuilder.js";
|
|
12
3
|
export default class ExpressionDecorator extends QueryDecorator {
|
|
@@ -20,15 +11,13 @@ export default class ExpressionDecorator extends QueryDecorator {
|
|
|
20
11
|
this.setHavingClauses();
|
|
21
12
|
this.setValueClauseKeywords();
|
|
22
13
|
}
|
|
23
|
-
build() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return context;
|
|
31
|
-
});
|
|
14
|
+
async build() {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const context = await this.component.build();
|
|
17
|
+
(_a = context.expressionSelect) !== null && _a !== void 0 ? _a : (context.expressionSelect = []);
|
|
18
|
+
context.expressionSelect.push(...this.parsedExpressions.map(e => e.baseExpressionClause));
|
|
19
|
+
(_b = context.conditions) !== null && _b !== void 0 ? _b : (context.conditions = {});
|
|
20
|
+
return context;
|
|
32
21
|
}
|
|
33
22
|
setWhereClauses() {
|
|
34
23
|
this.whereClauses = this.parsedExpressions
|
|
@@ -1,27 +1,16 @@
|
|
|
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
1
|
import QueryDecorator from "./QueryDecorator.js";
|
|
11
2
|
export default class GroupByDecorator extends QueryDecorator {
|
|
12
3
|
constructor(component, groupByColumns) {
|
|
13
4
|
super(component);
|
|
14
5
|
this.groupByColumns = groupByColumns;
|
|
15
6
|
}
|
|
16
|
-
build() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return context;
|
|
25
|
-
});
|
|
7
|
+
async build() {
|
|
8
|
+
var _a;
|
|
9
|
+
const context = await this.component.build();
|
|
10
|
+
if (this.groupByColumns) {
|
|
11
|
+
(_a = context.groupBy) !== null && _a !== void 0 ? _a : (context.groupBy = []);
|
|
12
|
+
context.groupBy.push(...this.groupByColumns);
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
26
15
|
}
|
|
27
16
|
}
|
|
@@ -1,12 +1,3 @@
|
|
|
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
1
|
import QueryDecorator from "./QueryDecorator.js";
|
|
11
2
|
export default class JoinDecorator extends QueryDecorator {
|
|
12
3
|
constructor(builder, layer, tableColumnInformation) {
|
|
@@ -26,37 +17,33 @@ export default class JoinDecorator extends QueryDecorator {
|
|
|
26
17
|
blacklistTables: (_e = layer.final) === null || _e === void 0 ? void 0 : _e.blacklistTables,
|
|
27
18
|
};
|
|
28
19
|
}
|
|
29
|
-
build() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return context;
|
|
39
|
-
});
|
|
20
|
+
async build() {
|
|
21
|
+
var _a;
|
|
22
|
+
const context = await this.component.build();
|
|
23
|
+
const selectExtensions = await this.buildJoinSelect();
|
|
24
|
+
const joinPart = this.buildJoinPart();
|
|
25
|
+
context.joinsSelect = selectExtensions;
|
|
26
|
+
(_a = context.joins) !== null && _a !== void 0 ? _a : (context.joins = []);
|
|
27
|
+
context.joins.push(...joinPart);
|
|
28
|
+
return context;
|
|
40
29
|
}
|
|
41
|
-
buildJoinSelect() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return [...mainSelect, ...joinedSelects.flat()].filter(s => s !== "").filter(Boolean);
|
|
59
|
-
});
|
|
30
|
+
async buildJoinSelect() {
|
|
31
|
+
var _a;
|
|
32
|
+
const blacklist = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.blacklistTables) || [];
|
|
33
|
+
const joinArray = Array.isArray(this.joins) ? this.joins : [this.joins];
|
|
34
|
+
const mainCols = this.tableColumnsCache.get(this.fromTableName) || [];
|
|
35
|
+
const mainSelect = mainCols
|
|
36
|
+
.filter(() => !blacklist.includes(this.fromTableName))
|
|
37
|
+
.map(col => `"${this.fromTableName}"."${col.name}" AS "${this.fromTableName}__${col.name}"`);
|
|
38
|
+
const joinedSelects = await Promise.all(joinArray.map(async (join) => {
|
|
39
|
+
if (blacklist.includes(join.fromTable))
|
|
40
|
+
return "";
|
|
41
|
+
const cols = this.tableColumnsCache.get(join.fromTable) || [];
|
|
42
|
+
return cols
|
|
43
|
+
.map(col => `"${join.fromTable}"."${col.name}" AS "${join.fromTable}__${col.name}"`)
|
|
44
|
+
.filter(col => col.trim() !== "");
|
|
45
|
+
}));
|
|
46
|
+
return [...mainSelect, ...joinedSelects.flat()].filter(s => s !== "").filter(Boolean);
|
|
60
47
|
}
|
|
61
48
|
buildJoinPart() {
|
|
62
49
|
const joinArray = Array.isArray(this.joins) ? this.joins : [this.joins];
|
|
@@ -1,12 +1,3 @@
|
|
|
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
1
|
import QueryDecorator from "./QueryDecorator.js";
|
|
11
2
|
export default class LimitDecorator extends QueryDecorator {
|
|
12
3
|
constructor(component, limitCount, offsetCount) {
|
|
@@ -14,16 +5,14 @@ export default class LimitDecorator extends QueryDecorator {
|
|
|
14
5
|
this.limitCount = limitCount;
|
|
15
6
|
this.offsetCount = offsetCount;
|
|
16
7
|
}
|
|
17
|
-
build() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return context;
|
|
27
|
-
});
|
|
8
|
+
async build() {
|
|
9
|
+
const context = await this.component.build();
|
|
10
|
+
if (this.limitCount) {
|
|
11
|
+
context.limit = this.limitCount;
|
|
12
|
+
}
|
|
13
|
+
if (this.offsetCount) {
|
|
14
|
+
context.offset = this.offsetCount;
|
|
15
|
+
}
|
|
16
|
+
return context;
|
|
28
17
|
}
|
|
29
18
|
}
|
|
@@ -1,27 +1,16 @@
|
|
|
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
1
|
import QueryDecorator from "./QueryDecorator.js";
|
|
11
2
|
export default class OrderByDecorator extends QueryDecorator {
|
|
12
3
|
constructor(component, orderByColumns) {
|
|
13
4
|
super(component);
|
|
14
5
|
this.orderByColumns = orderByColumns;
|
|
15
6
|
}
|
|
16
|
-
build() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return context;
|
|
25
|
-
});
|
|
7
|
+
async build() {
|
|
8
|
+
var _a;
|
|
9
|
+
const context = await this.component.build();
|
|
10
|
+
if (this.orderByColumns) {
|
|
11
|
+
(_a = context.orderBy) !== null && _a !== void 0 ? _a : (context.orderBy = []);
|
|
12
|
+
context.orderBy.push(...this.orderByColumns);
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
26
15
|
}
|
|
27
16
|
}
|