@iamkirbki/database-handler-core 4.4.2 → 4.4.4
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.js +34 -46
- package/dist/base/Query.js +56 -79
- package/dist/base/Record.js +75 -90
- package/dist/base/Table.js +128 -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 +72 -97
- package/package.json +1 -1
package/dist/base/Record.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 { inspect } from "util";
|
|
11
2
|
import Query from "./Query.js";
|
|
12
3
|
import QueryStatementBuilder from "../helpers/QueryBuilders/QueryStatementBuilder.js";
|
|
@@ -26,94 +17,88 @@ export default class Record {
|
|
|
26
17
|
return this._values;
|
|
27
18
|
}
|
|
28
19
|
;
|
|
29
|
-
Insert() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
recordFactory: this._recordFactory
|
|
43
|
-
});
|
|
44
|
-
const result = yield query.Run();
|
|
45
|
-
let recordId;
|
|
46
|
-
// For PostgreSQL compatibility: use 'id' from values if lastInsertRowid is undefined
|
|
47
|
-
if (Array.isArray(this._values)) {
|
|
48
|
-
recordId = (_a = result === null || result === void 0 ? void 0 : result.lastInsertRowid) !== null && _a !== void 0 ? _a : this._values.map(v => v.column === 'id' ? v.value : undefined);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
recordId = (_b = result === null || result === void 0 ? void 0 : result.lastInsertRowid) !== null && _b !== void 0 ? _b : this._values.id;
|
|
52
|
-
}
|
|
53
|
-
if (recordId === undefined) {
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
const builder = new QueryStatementBuilder({ base: { from: this._tableName, where: Object.assign({}, this._values) } });
|
|
57
|
-
const queryStrSelect = yield builder.build();
|
|
58
|
-
const querySelect = this._queryFactory({
|
|
59
|
-
tableName: this._tableName,
|
|
60
|
-
query: queryStrSelect,
|
|
61
|
-
parameters: this._values,
|
|
62
|
-
adapterName: this._customAdapter,
|
|
63
|
-
recordFactory: this._recordFactory
|
|
64
|
-
});
|
|
65
|
-
const insertedRecord = yield querySelect.All();
|
|
66
|
-
if (insertedRecord.length > 0) {
|
|
67
|
-
this._values = insertedRecord[insertedRecord.length - 1].values;
|
|
68
|
-
}
|
|
69
|
-
this._values = Object.assign(Object.assign({}, this._values), { id: recordId });
|
|
70
|
-
return this;
|
|
20
|
+
async Insert() {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
const columns = Object.keys(this._values);
|
|
23
|
+
if (columns.length === 0) {
|
|
24
|
+
throw new Error("Cannot insert record with no columns");
|
|
25
|
+
}
|
|
26
|
+
const queryStr = await oldQueryStatementBuilder.BuildInsert(this._tableName, this._values);
|
|
27
|
+
const query = this._queryFactory({
|
|
28
|
+
tableName: this._tableName,
|
|
29
|
+
query: queryStr,
|
|
30
|
+
parameters: this._values,
|
|
31
|
+
adapterName: this._customAdapter,
|
|
32
|
+
recordFactory: this._recordFactory
|
|
71
33
|
});
|
|
34
|
+
const result = await query.Run();
|
|
35
|
+
let recordId;
|
|
36
|
+
// For PostgreSQL compatibility: use 'id' from values if lastInsertRowid is undefined
|
|
37
|
+
if (Array.isArray(this._values)) {
|
|
38
|
+
recordId = (_a = result === null || result === void 0 ? void 0 : result.lastInsertRowid) !== null && _a !== void 0 ? _a : this._values.map(v => v.column === 'id' ? v.value : undefined);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
recordId = (_b = result === null || result === void 0 ? void 0 : result.lastInsertRowid) !== null && _b !== void 0 ? _b : this._values.id;
|
|
42
|
+
}
|
|
43
|
+
if (recordId === undefined) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const builder = new QueryStatementBuilder({ base: { from: this._tableName, where: { ...this._values } } });
|
|
47
|
+
const queryStrSelect = await builder.build();
|
|
48
|
+
const querySelect = this._queryFactory({
|
|
49
|
+
tableName: this._tableName,
|
|
50
|
+
query: queryStrSelect,
|
|
51
|
+
parameters: this._values,
|
|
52
|
+
adapterName: this._customAdapter,
|
|
53
|
+
recordFactory: this._recordFactory
|
|
54
|
+
});
|
|
55
|
+
const insertedRecord = await querySelect.All();
|
|
56
|
+
if (insertedRecord.length > 0) {
|
|
57
|
+
this._values = insertedRecord[insertedRecord.length - 1].values;
|
|
58
|
+
}
|
|
59
|
+
this._values = { ...this._values, id: recordId };
|
|
60
|
+
return this;
|
|
72
61
|
}
|
|
73
62
|
/** Update this record in the database */
|
|
74
|
-
Update(newValues, whereParameters) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
recordFactory: this._recordFactory
|
|
92
|
-
});
|
|
93
|
-
yield _query.Run();
|
|
94
|
-
this._values = Object.assign(Object.assign({}, this._values), newValues);
|
|
95
|
-
return this;
|
|
63
|
+
async Update(newValues, whereParameters) {
|
|
64
|
+
const originalValues = this._values;
|
|
65
|
+
if (originalValues.updated_at !== undefined) {
|
|
66
|
+
newValues.updated_at = new Date().toISOString();
|
|
67
|
+
}
|
|
68
|
+
const queryStr = await oldQueryStatementBuilder.BuildUpdate(this._tableName, newValues, whereParameters);
|
|
69
|
+
// Merge newValues and originalValues for parameters (with 'where_' prefix for where clause)
|
|
70
|
+
const params = { ...newValues };
|
|
71
|
+
Object.entries(originalValues).forEach(([key, value]) => {
|
|
72
|
+
params[`where_${key}`] = value;
|
|
73
|
+
});
|
|
74
|
+
const _query = this._queryFactory({
|
|
75
|
+
tableName: this._tableName,
|
|
76
|
+
query: queryStr,
|
|
77
|
+
parameters: params,
|
|
78
|
+
adapterName: this._customAdapter,
|
|
79
|
+
recordFactory: this._recordFactory
|
|
96
80
|
});
|
|
81
|
+
await _query.Run();
|
|
82
|
+
this._values = { ...this._values, ...newValues };
|
|
83
|
+
return this;
|
|
97
84
|
}
|
|
98
85
|
/** Delete this record from the database */
|
|
99
|
-
Delete(primaryKey) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
recordFactory: this._recordFactory
|
|
114
|
-
});
|
|
115
|
-
yield _query.Run();
|
|
86
|
+
async Delete(primaryKey) {
|
|
87
|
+
const originalValues = this._values;
|
|
88
|
+
if (originalValues.deleted_at !== undefined) {
|
|
89
|
+
this._values.deleted_at = new Date().toISOString();
|
|
90
|
+
await this.Update(this._values, this._values.id ? { id: this._values.id } : primaryKey || {});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const queryStr = await oldQueryStatementBuilder.BuildDelete(this._tableName, this._values);
|
|
94
|
+
const _query = this._queryFactory({
|
|
95
|
+
tableName: this._tableName,
|
|
96
|
+
query: queryStr,
|
|
97
|
+
parameters: this.values,
|
|
98
|
+
adapterName: this._customAdapter,
|
|
99
|
+
recordFactory: this._recordFactory
|
|
116
100
|
});
|
|
101
|
+
await _query.Run();
|
|
117
102
|
}
|
|
118
103
|
/** Returns the values object for JSON.stringify() */
|
|
119
104
|
toJSON() {
|
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,160 @@ 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);
|
|
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) {
|
|
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
|
+
(_a = joinedTableData[tableName]) !== null && _a !== void 0 ? _a : (joinedTableData[tableName] = {});
|
|
145
|
+
joinedTableData[tableName][columnName] = value;
|
|
172
146
|
}
|
|
173
147
|
}
|
|
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);
|
|
148
|
+
else {
|
|
149
|
+
mainTableData[aliasedKey] = value;
|
|
192
150
|
}
|
|
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
151
|
}
|
|
152
|
+
const filteredJoinedData = Object.fromEntries(
|
|
153
|
+
// eslint-disable-next-line no-unused-vars
|
|
154
|
+
Object.entries(joinedTableData).filter(([_, data]) => Object.keys(data).length > 0));
|
|
155
|
+
const combinedData = { ...mainTableData, ...filteredJoinedData };
|
|
156
|
+
return this._recordFactory(this._name, combinedData, this._customAdapter);
|
|
200
157
|
});
|
|
201
158
|
}
|
|
159
|
+
async toSql(queryLayers) {
|
|
160
|
+
if (queryLayers.base.joins && queryLayers.base.joins.length > 0) {
|
|
161
|
+
const joinedTables = queryLayers.base.joins.map(j => j.fromTable);
|
|
162
|
+
const tableColumnCache = new Map();
|
|
163
|
+
const columnInfo = await this._query.TableColumnInformation(this._name);
|
|
164
|
+
tableColumnCache.set(this._name, columnInfo);
|
|
165
|
+
for (const tableName of joinedTables) {
|
|
166
|
+
const columnInfo = await this._query.TableColumnInformation(tableName);
|
|
167
|
+
tableColumnCache.set(tableName, columnInfo);
|
|
168
|
+
}
|
|
169
|
+
const builder = new QueryStatementBuilder(queryLayers, tableColumnCache);
|
|
170
|
+
return await builder.build();
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
const builder = new QueryStatementBuilder(queryLayers);
|
|
174
|
+
return await builder.build();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
202
177
|
}
|
|
@@ -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
|
}
|