remult 0.14.6 → 0.14.7
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/assign.js +5 -1
- package/classType.js +2 -1
- package/graphql.js +146 -84
- package/index.js +73 -25
- package/inputTypes.js +16 -9
- package/package.json +1 -2
- package/postgres/index.js +4 -1
- package/postgres/postgres-data-provider.d.ts +4 -1
- package/postgres/postgres-data-provider.js +364 -165
- package/postgres/postgresColumnSyntax.d.ts +1 -1
- package/postgres/postgresColumnSyntax.js +8 -4
- package/remult-express.js +10 -6
- package/remult-knex/index.d.ts +5 -2
- package/remult-knex/index.js +720 -300
- package/remult-middleware.js +29 -24
- package/remult-mongo.js +406 -172
- package/server/JsonEntityFileStorage.js +15 -10
- package/server/expressBridge.d.ts +4 -2
- package/server/expressBridge.js +570 -383
- package/server/index.js +11 -4
- package/server/register-actions-on-server.js +38 -12
- package/server/register-entities-on-server.js +13 -9
- package/src/__EntityValueProvider.js +2 -1
- package/src/__RowsOfDataForTesting.js +2 -1
- package/src/backend-tests/backend-database-test-setup.backend-spec.js +190 -72
- package/src/backend-tests/my-test.backend-spec.js +114 -45
- package/src/column-interfaces.js +6 -2
- package/src/column.js +113 -71
- package/src/context.js +330 -174
- package/src/data-api.js +326 -162
- package/src/data-interfaces.js +11 -7
- package/src/data-providers/array-entity-data-provider.js +286 -171
- package/src/data-providers/in-memory-database.js +27 -12
- package/src/data-providers/json-data-provider.js +77 -41
- package/src/data-providers/rest-data-provider.js +189 -102
- package/src/data-providers/sql-database.js +403 -223
- package/src/data-providers/web-sql-data-provider.js +139 -78
- package/src/entity.js +2 -1
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +1 -1
- package/src/filter/filter-consumer-bridge-to-sql-request.js +248 -106
- package/src/filter/filter-consumer-bridge-to-url-builder.js +2 -1
- package/src/filter/filter-interfaces.js +440 -277
- package/src/id-entity.js +17 -8
- package/src/remult3/RepositoryImplementation.js +2367 -1191
- package/src/remult3/index.js +5 -2
- package/src/remult3/remult3.js +2 -1
- package/src/server-action.js +528 -294
- package/src/shared-tests/db-tests-setup.js +153 -49
- package/src/shared-tests/db-tests.db-tests.js +1566 -660
- package/src/shared-tests/deleteAll.js +20 -3
- package/src/shared-tests/entityWithValidations.js +79 -52
- package/src/shared-tests/index.js +6 -4
- package/src/shared-tests/test-custom-id-column.spec.js +85 -37
- package/src/shared-tests/test-special-value.spec.js +104 -64
- package/src/shared-tests/test-update-with-null.spec.js +49 -28
- package/src/sort.js +95 -38
- package/src/sql-command.js +2 -1
- package/src/tests/Done.js +13 -7
- package/src/tests/TestDataApiResponse.js +22 -15
- package/src/tests/c.js +27 -21
- package/src/tests/createData.js +48 -20
- package/src/tests/d.js +27 -19
- package/src/tests/dWithPrefilter.js +44 -31
- package/src/tests/entityForCustomFilter.js +66 -42
- package/src/tests/entityWithValidationsOnColumn.js +29 -21
- package/src/tests/frontend-database-tests-setup.spec.js +98 -35
- package/src/tests/h.js +44 -35
- package/src/tests/remult-3-entities.js +80 -71
- package/src/tests/tasks.js +29 -23
- package/src/tests/testHelper.spec.js +322 -170
- package/src/tests/testModel/models.js +33 -25
- package/src/validators.js +59 -32
- package/urlBuilder.js +14 -8
- package/valueConverters.js +160 -161
|
@@ -1,173 +1,283 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SqlDatabase = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var column_1 = require("../column");
|
|
6
|
+
var filter_consumer_bridge_to_sql_request_1 = require("../filter/filter-consumer-bridge-to-sql-request");
|
|
7
|
+
var filter_interfaces_1 = require("../filter/filter-interfaces");
|
|
8
|
+
var sort_1 = require("../sort");
|
|
5
9
|
// @dynamic
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
var SqlDatabase = /** @class */ (function () {
|
|
11
|
+
function SqlDatabase(sql) {
|
|
8
12
|
this.sql = sql;
|
|
9
13
|
this.createdEntities = [];
|
|
10
14
|
}
|
|
11
|
-
createCommand() {
|
|
15
|
+
SqlDatabase.prototype.createCommand = function () {
|
|
12
16
|
return new LogSQLCommand(this.sql.createCommand(), SqlDatabase.LogToConsole);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
}, this.sql);
|
|
24
|
-
}
|
|
25
|
-
transaction(action) {
|
|
26
|
-
return this.sql.transaction(async (x) => {
|
|
27
|
-
let completed = false;
|
|
28
|
-
try {
|
|
29
|
-
await action(new SqlDatabase({
|
|
30
|
-
createCommand: () => {
|
|
31
|
-
let c = x.createCommand();
|
|
32
|
-
return {
|
|
33
|
-
addParameterAndReturnSqlToken: x => c.addParameterAndReturnSqlToken(x),
|
|
34
|
-
execute: async (sql) => {
|
|
35
|
-
if (completed)
|
|
36
|
-
throw "can't run a command after the transaction was completed";
|
|
37
|
-
return c.execute(sql);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
getLimitSqlSyntax: this.sql.getLimitSqlSyntax,
|
|
42
|
-
entityIsUsedForTheFirstTime: y => x.entityIsUsedForTheFirstTime(y),
|
|
43
|
-
transaction: z => x.transaction(z),
|
|
44
|
-
}));
|
|
45
|
-
}
|
|
46
|
-
finally {
|
|
47
|
-
completed = true;
|
|
48
|
-
}
|
|
17
|
+
};
|
|
18
|
+
SqlDatabase.prototype.execute = function (sql) {
|
|
19
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
20
|
+
return tslib_1.__generator(this, function (_a) {
|
|
21
|
+
switch (_a.label) {
|
|
22
|
+
case 0: return [4 /*yield*/, this.createCommand().execute(sql)];
|
|
23
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
49
26
|
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
27
|
+
};
|
|
28
|
+
SqlDatabase.prototype.getEntityDataProvider = function (entity) {
|
|
29
|
+
var _this = this;
|
|
30
|
+
return new ActualSQLServerDataProvider(entity, this, function (dbName) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
31
|
+
return tslib_1.__generator(this, function (_a) {
|
|
32
|
+
switch (_a.label) {
|
|
33
|
+
case 0:
|
|
34
|
+
if (!(this.createdEntities.indexOf(dbName.entityName) < 0)) return [3 /*break*/, 2];
|
|
35
|
+
this.createdEntities.push(dbName.entityName);
|
|
36
|
+
return [4 /*yield*/, this.sql.entityIsUsedForTheFirstTime(entity)];
|
|
37
|
+
case 1:
|
|
38
|
+
_a.sent();
|
|
39
|
+
_a.label = 2;
|
|
40
|
+
case 2: return [2 /*return*/];
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}); }, this.sql);
|
|
44
|
+
};
|
|
45
|
+
SqlDatabase.prototype.transaction = function (action) {
|
|
46
|
+
var _this = this;
|
|
47
|
+
return this.sql.transaction(function (x) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
48
|
+
var completed;
|
|
49
|
+
var _this = this;
|
|
50
|
+
return tslib_1.__generator(this, function (_a) {
|
|
51
|
+
switch (_a.label) {
|
|
52
|
+
case 0:
|
|
53
|
+
completed = false;
|
|
54
|
+
_a.label = 1;
|
|
55
|
+
case 1:
|
|
56
|
+
_a.trys.push([1, , 3, 4]);
|
|
57
|
+
return [4 /*yield*/, action(new SqlDatabase({
|
|
58
|
+
createCommand: function () {
|
|
59
|
+
var c = x.createCommand();
|
|
60
|
+
return {
|
|
61
|
+
addParameterAndReturnSqlToken: function (x) { return c.addParameterAndReturnSqlToken(x); },
|
|
62
|
+
execute: function (sql) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
63
|
+
return tslib_1.__generator(this, function (_a) {
|
|
64
|
+
if (completed)
|
|
65
|
+
throw "can't run a command after the transaction was completed";
|
|
66
|
+
return [2 /*return*/, c.execute(sql)];
|
|
67
|
+
});
|
|
68
|
+
}); }
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
getLimitSqlSyntax: this.sql.getLimitSqlSyntax,
|
|
72
|
+
entityIsUsedForTheFirstTime: function (y) { return x.entityIsUsedForTheFirstTime(y); },
|
|
73
|
+
transaction: function (z) { return x.transaction(z); },
|
|
74
|
+
}))];
|
|
75
|
+
case 2:
|
|
76
|
+
_a.sent();
|
|
77
|
+
return [3 /*break*/, 4];
|
|
78
|
+
case 3:
|
|
79
|
+
completed = true;
|
|
80
|
+
return [7 /*endfinally*/];
|
|
81
|
+
case 4: return [2 /*return*/];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}); });
|
|
85
|
+
};
|
|
86
|
+
SqlDatabase.customFilter = function (build) {
|
|
87
|
+
var _a;
|
|
88
|
+
return _a = {},
|
|
89
|
+
_a[filter_interfaces_1.customDatabaseFilterToken] = {
|
|
54
90
|
buildSql: build
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
SqlDatabase.
|
|
60
|
-
SqlDatabase
|
|
61
|
-
|
|
62
|
-
|
|
91
|
+
},
|
|
92
|
+
_a;
|
|
93
|
+
};
|
|
94
|
+
SqlDatabase.LogToConsole = false;
|
|
95
|
+
SqlDatabase.durationThreshold = 0;
|
|
96
|
+
return SqlDatabase;
|
|
97
|
+
}());
|
|
98
|
+
exports.SqlDatabase = SqlDatabase;
|
|
99
|
+
var LogSQLCommand = /** @class */ (function () {
|
|
100
|
+
function LogSQLCommand(origin, allQueries) {
|
|
63
101
|
this.origin = origin;
|
|
64
102
|
this.allQueries = allQueries;
|
|
65
103
|
this.args = {};
|
|
66
104
|
}
|
|
67
|
-
addParameterAndReturnSqlToken(val) {
|
|
68
|
-
|
|
105
|
+
LogSQLCommand.prototype.addParameterAndReturnSqlToken = function (val) {
|
|
106
|
+
var r = this.origin.addParameterAndReturnSqlToken(val);
|
|
69
107
|
this.args[r] = val;
|
|
70
108
|
return r;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
109
|
+
};
|
|
110
|
+
LogSQLCommand.prototype.execute = function (sql) {
|
|
111
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
112
|
+
var start, r, d, err_1;
|
|
113
|
+
return tslib_1.__generator(this, function (_a) {
|
|
114
|
+
switch (_a.label) {
|
|
115
|
+
case 0:
|
|
116
|
+
_a.trys.push([0, 2, , 3]);
|
|
117
|
+
start = new Date();
|
|
118
|
+
return [4 /*yield*/, this.origin.execute(sql)];
|
|
119
|
+
case 1:
|
|
120
|
+
r = _a.sent();
|
|
121
|
+
if (this.allQueries) {
|
|
122
|
+
d = new Date().valueOf() - start.valueOf();
|
|
123
|
+
if (d > SqlDatabase.durationThreshold) {
|
|
124
|
+
console.log({ query: sql, arguments: this.args, duration: d / 1000 });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return [2 /*return*/, r];
|
|
128
|
+
case 2:
|
|
129
|
+
err_1 = _a.sent();
|
|
130
|
+
console.error({ error: err_1, query: sql, arguments: this.args });
|
|
131
|
+
throw err_1;
|
|
132
|
+
case 3: return [2 /*return*/];
|
|
80
133
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
class ActualSQLServerDataProvider {
|
|
91
|
-
constructor(entity, sql, iAmUsed, strategy) {
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
return LogSQLCommand;
|
|
138
|
+
}());
|
|
139
|
+
var ActualSQLServerDataProvider = /** @class */ (function () {
|
|
140
|
+
function ActualSQLServerDataProvider(entity, sql, iAmUsed, strategy) {
|
|
92
141
|
this.entity = entity;
|
|
93
142
|
this.sql = sql;
|
|
94
143
|
this.iAmUsed = iAmUsed;
|
|
95
144
|
this.strategy = strategy;
|
|
96
145
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return r.execute(select).then(r => {
|
|
112
|
-
return +r.rows[0].count;
|
|
146
|
+
ActualSQLServerDataProvider.prototype.init = function () {
|
|
147
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
148
|
+
var dbNameProvider;
|
|
149
|
+
return tslib_1.__generator(this, function (_a) {
|
|
150
|
+
switch (_a.label) {
|
|
151
|
+
case 0: return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.getDbNameProvider(this.entity)];
|
|
152
|
+
case 1:
|
|
153
|
+
dbNameProvider = _a.sent();
|
|
154
|
+
return [4 /*yield*/, this.iAmUsed(dbNameProvider)];
|
|
155
|
+
case 2:
|
|
156
|
+
_a.sent();
|
|
157
|
+
return [2 /*return*/, dbNameProvider];
|
|
158
|
+
}
|
|
159
|
+
});
|
|
113
160
|
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
else
|
|
138
|
-
segs.push(s);
|
|
161
|
+
};
|
|
162
|
+
ActualSQLServerDataProvider.prototype.count = function (where) {
|
|
163
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
164
|
+
var e, select, r, wc, _a;
|
|
165
|
+
return tslib_1.__generator(this, function (_b) {
|
|
166
|
+
switch (_b.label) {
|
|
167
|
+
case 0: return [4 /*yield*/, this.init()];
|
|
168
|
+
case 1:
|
|
169
|
+
e = _b.sent();
|
|
170
|
+
select = 'select count(*) count from ' + e.entityName;
|
|
171
|
+
r = this.sql.createCommand();
|
|
172
|
+
if (!where) return [3 /*break*/, 3];
|
|
173
|
+
wc = new filter_consumer_bridge_to_sql_request_1.FilterConsumerBridgeToSqlRequest(r, e);
|
|
174
|
+
where.__applyToConsumer(wc);
|
|
175
|
+
_a = select;
|
|
176
|
+
return [4 /*yield*/, wc.resolveWhere()];
|
|
177
|
+
case 2:
|
|
178
|
+
select = _a + _b.sent();
|
|
179
|
+
_b.label = 3;
|
|
180
|
+
case 3: return [2 /*return*/, r.execute(select).then(function (r) {
|
|
181
|
+
return +r.rows[0].count;
|
|
182
|
+
})];
|
|
139
183
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
ActualSQLServerDataProvider.prototype.find = function (options) {
|
|
188
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
189
|
+
var e, _a, colKeys, select, r, where, _b, first, segs, _loop_1, _c, _d, s, segs_1, segs_1_1, c, page;
|
|
190
|
+
var e_1, _e, e_2, _f;
|
|
191
|
+
var _this = this;
|
|
192
|
+
return tslib_1.__generator(this, function (_g) {
|
|
193
|
+
switch (_g.label) {
|
|
194
|
+
case 0: return [4 /*yield*/, this.init()];
|
|
195
|
+
case 1:
|
|
196
|
+
e = _g.sent();
|
|
197
|
+
_a = this.buildSelect(e), colKeys = _a.colKeys, select = _a.select;
|
|
198
|
+
select = 'select ' + select;
|
|
199
|
+
select += '\n from ' + e.entityName;
|
|
200
|
+
r = this.sql.createCommand();
|
|
201
|
+
if (!options) return [3 /*break*/, 4];
|
|
202
|
+
if (!options.where) return [3 /*break*/, 3];
|
|
203
|
+
where = new filter_consumer_bridge_to_sql_request_1.FilterConsumerBridgeToSqlRequest(r, e);
|
|
204
|
+
options.where.__applyToConsumer(where);
|
|
205
|
+
_b = select;
|
|
206
|
+
return [4 /*yield*/, where.resolveWhere()];
|
|
207
|
+
case 2:
|
|
208
|
+
select = _b + _g.sent();
|
|
209
|
+
_g.label = 3;
|
|
210
|
+
case 3:
|
|
211
|
+
if (options.limit) {
|
|
212
|
+
options.orderBy = sort_1.Sort.createUniqueSort(this.entity, options.orderBy);
|
|
213
|
+
}
|
|
214
|
+
if (options.orderBy) {
|
|
215
|
+
first = true;
|
|
216
|
+
segs = [];
|
|
217
|
+
_loop_1 = function (s) {
|
|
218
|
+
if (s.field instanceof column_1.CompoundIdField) {
|
|
219
|
+
segs.push.apply(segs, tslib_1.__spread(s.field.fields.map(function (c) { return ({ field: c, isDescending: s.isDescending }); })));
|
|
220
|
+
}
|
|
221
|
+
else
|
|
222
|
+
segs.push(s);
|
|
223
|
+
};
|
|
224
|
+
try {
|
|
225
|
+
for (_c = tslib_1.__values(options.orderBy.Segments), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
226
|
+
s = _d.value;
|
|
227
|
+
_loop_1(s);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
231
|
+
finally {
|
|
232
|
+
try {
|
|
233
|
+
if (_d && !_d.done && (_e = _c.return)) _e.call(_c);
|
|
234
|
+
}
|
|
235
|
+
finally { if (e_1) throw e_1.error; }
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
for (segs_1 = tslib_1.__values(segs), segs_1_1 = segs_1.next(); !segs_1_1.done; segs_1_1 = segs_1.next()) {
|
|
239
|
+
c = segs_1_1.value;
|
|
240
|
+
if (first) {
|
|
241
|
+
select += ' Order By ';
|
|
242
|
+
first = false;
|
|
243
|
+
}
|
|
244
|
+
else
|
|
245
|
+
select += ', ';
|
|
246
|
+
select += e.nameOf(c.field);
|
|
247
|
+
if (c.isDescending)
|
|
248
|
+
select += ' desc';
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
252
|
+
finally {
|
|
253
|
+
try {
|
|
254
|
+
if (segs_1_1 && !segs_1_1.done && (_f = segs_1.return)) _f.call(segs_1);
|
|
255
|
+
}
|
|
256
|
+
finally { if (e_2) throw e_2.error; }
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (options.limit) {
|
|
260
|
+
page = 1;
|
|
261
|
+
if (options.page)
|
|
262
|
+
page = options.page;
|
|
263
|
+
if (page < 1)
|
|
264
|
+
page = 1;
|
|
265
|
+
select += ' ' + this.strategy.getLimitSqlSyntax(options.limit, (page - 1) * options.limit);
|
|
266
|
+
}
|
|
267
|
+
_g.label = 4;
|
|
268
|
+
case 4: return [2 /*return*/, r.execute(select).then(function (r) {
|
|
269
|
+
return r.rows.map(function (y) {
|
|
270
|
+
return _this.buildResultRow(colKeys, y, r);
|
|
271
|
+
});
|
|
272
|
+
})];
|
|
150
273
|
}
|
|
151
|
-
}
|
|
152
|
-
if (options.limit) {
|
|
153
|
-
let page = 1;
|
|
154
|
-
if (options.page)
|
|
155
|
-
page = options.page;
|
|
156
|
-
if (page < 1)
|
|
157
|
-
page = 1;
|
|
158
|
-
select += ' ' + this.strategy.getLimitSqlSyntax(options.limit, (page - 1) * options.limit);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return r.execute(select).then(r => {
|
|
162
|
-
return r.rows.map(y => {
|
|
163
|
-
return this.buildResultRow(colKeys, y, r);
|
|
164
274
|
});
|
|
165
275
|
});
|
|
166
|
-
}
|
|
167
|
-
buildResultRow(colKeys, y, r) {
|
|
168
|
-
|
|
169
|
-
for (
|
|
170
|
-
|
|
276
|
+
};
|
|
277
|
+
ActualSQLServerDataProvider.prototype.buildResultRow = function (colKeys, y, r) {
|
|
278
|
+
var result = {};
|
|
279
|
+
for (var index = 0; index < colKeys.length; index++) {
|
|
280
|
+
var col = colKeys[index];
|
|
171
281
|
try {
|
|
172
282
|
result[col.key] = col.valueConverter.fromDb(y[r.getColumnKeyInResultForIndexInSelect(index)]);
|
|
173
283
|
}
|
|
@@ -176,86 +286,156 @@ class ActualSQLServerDataProvider {
|
|
|
176
286
|
}
|
|
177
287
|
}
|
|
178
288
|
return result;
|
|
179
|
-
}
|
|
180
|
-
buildSelect(e) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
289
|
+
};
|
|
290
|
+
ActualSQLServerDataProvider.prototype.buildSelect = function (e) {
|
|
291
|
+
var e_3, _a;
|
|
292
|
+
var select = '';
|
|
293
|
+
var colKeys = [];
|
|
294
|
+
try {
|
|
295
|
+
for (var _b = tslib_1.__values(this.entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
296
|
+
var x = _c.value;
|
|
297
|
+
if (x.isServerExpression) {
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
if (colKeys.length > 0)
|
|
301
|
+
select += ', ';
|
|
302
|
+
select += e.nameOf(x);
|
|
303
|
+
colKeys.push(x);
|
|
304
|
+
}
|
|
191
305
|
}
|
|
192
306
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
let r = this.sql.createCommand();
|
|
198
|
-
let f = new FilterConsumerBridgeToSqlRequest(r, e);
|
|
199
|
-
Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
200
|
-
let statement = 'update ' + e.entityName + ' set ';
|
|
201
|
-
let added = false;
|
|
202
|
-
for (const x of this.entity.fields) {
|
|
203
|
-
if (x instanceof CompoundIdField) {
|
|
204
|
-
}
|
|
205
|
-
if (e.isDbReadonly(x)) { }
|
|
206
|
-
else if (data[x.key] !== undefined) {
|
|
207
|
-
let v = x.valueConverter.toDb(data[x.key]);
|
|
208
|
-
if (v !== undefined) {
|
|
209
|
-
if (!added)
|
|
210
|
-
added = true;
|
|
211
|
-
else
|
|
212
|
-
statement += ', ';
|
|
213
|
-
statement += e.nameOf(x) + ' = ' + r.addParameterAndReturnSqlToken(v);
|
|
214
|
-
}
|
|
307
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
308
|
+
finally {
|
|
309
|
+
try {
|
|
310
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
215
311
|
}
|
|
312
|
+
finally { if (e_3) throw e_3.error; }
|
|
216
313
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return
|
|
221
|
-
|
|
314
|
+
return { colKeys: colKeys, select: select };
|
|
315
|
+
};
|
|
316
|
+
ActualSQLServerDataProvider.prototype.update = function (id, data) {
|
|
317
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
318
|
+
var e, r, f, statement, added, _a, _b, x, v, _c, _d, colKeys, select;
|
|
319
|
+
var e_4, _e;
|
|
320
|
+
var _this = this;
|
|
321
|
+
return tslib_1.__generator(this, function (_f) {
|
|
322
|
+
switch (_f.label) {
|
|
323
|
+
case 0: return [4 /*yield*/, this.init()];
|
|
324
|
+
case 1:
|
|
325
|
+
e = _f.sent();
|
|
326
|
+
r = this.sql.createCommand();
|
|
327
|
+
f = new filter_consumer_bridge_to_sql_request_1.FilterConsumerBridgeToSqlRequest(r, e);
|
|
328
|
+
filter_interfaces_1.Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
329
|
+
statement = 'update ' + e.entityName + ' set ';
|
|
330
|
+
added = false;
|
|
331
|
+
try {
|
|
332
|
+
for (_a = tslib_1.__values(this.entity.fields), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
333
|
+
x = _b.value;
|
|
334
|
+
if (x instanceof column_1.CompoundIdField) {
|
|
335
|
+
}
|
|
336
|
+
if (e.isDbReadonly(x)) { }
|
|
337
|
+
else if (data[x.key] !== undefined) {
|
|
338
|
+
v = x.valueConverter.toDb(data[x.key]);
|
|
339
|
+
if (v !== undefined) {
|
|
340
|
+
if (!added)
|
|
341
|
+
added = true;
|
|
342
|
+
else
|
|
343
|
+
statement += ', ';
|
|
344
|
+
statement += e.nameOf(x) + ' = ' + r.addParameterAndReturnSqlToken(v);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
350
|
+
finally {
|
|
351
|
+
try {
|
|
352
|
+
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
353
|
+
}
|
|
354
|
+
finally { if (e_4) throw e_4.error; }
|
|
355
|
+
}
|
|
356
|
+
_c = statement;
|
|
357
|
+
return [4 /*yield*/, f.resolveWhere()];
|
|
358
|
+
case 2:
|
|
359
|
+
statement = _c + _f.sent();
|
|
360
|
+
_d = this.buildSelect(e), colKeys = _d.colKeys, select = _d.select;
|
|
361
|
+
statement += ' returning ' + select;
|
|
362
|
+
return [2 /*return*/, r.execute(statement).then(function (sqlResult) {
|
|
363
|
+
return _this.buildResultRow(colKeys, sqlResult.rows[0], sqlResult);
|
|
364
|
+
})];
|
|
365
|
+
}
|
|
366
|
+
});
|
|
222
367
|
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
else {
|
|
242
|
-
let v = x.valueConverter.toDb(data[x.key]);
|
|
243
|
-
if (v != undefined) {
|
|
244
|
-
if (!added)
|
|
245
|
-
added = true;
|
|
246
|
-
else {
|
|
247
|
-
cols += ', ';
|
|
248
|
-
vals += ', ';
|
|
249
|
-
}
|
|
250
|
-
cols += e.nameOf(x);
|
|
251
|
-
vals += r.addParameterAndReturnSqlToken(v);
|
|
368
|
+
};
|
|
369
|
+
ActualSQLServerDataProvider.prototype.delete = function (id) {
|
|
370
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
371
|
+
var e, r, f, statement, _a;
|
|
372
|
+
return tslib_1.__generator(this, function (_b) {
|
|
373
|
+
switch (_b.label) {
|
|
374
|
+
case 0: return [4 /*yield*/, this.init()];
|
|
375
|
+
case 1:
|
|
376
|
+
e = _b.sent();
|
|
377
|
+
r = this.sql.createCommand();
|
|
378
|
+
f = new filter_consumer_bridge_to_sql_request_1.FilterConsumerBridgeToSqlRequest(r, e);
|
|
379
|
+
filter_interfaces_1.Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
380
|
+
statement = 'delete from ' + e.entityName;
|
|
381
|
+
_a = statement;
|
|
382
|
+
return [4 /*yield*/, f.resolveWhere()];
|
|
383
|
+
case 2:
|
|
384
|
+
statement = _a + _b.sent();
|
|
385
|
+
return [2 /*return*/, r.execute(statement).then(function () { })];
|
|
252
386
|
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
ActualSQLServerDataProvider.prototype.insert = function (data) {
|
|
391
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
392
|
+
var e, r, cols, vals, added, _a, _b, x, v, statement, _c, colKeys, select;
|
|
393
|
+
var e_5, _d;
|
|
394
|
+
var _this = this;
|
|
395
|
+
return tslib_1.__generator(this, function (_e) {
|
|
396
|
+
switch (_e.label) {
|
|
397
|
+
case 0: return [4 /*yield*/, this.init()];
|
|
398
|
+
case 1:
|
|
399
|
+
e = _e.sent();
|
|
400
|
+
r = this.sql.createCommand();
|
|
401
|
+
cols = '';
|
|
402
|
+
vals = '';
|
|
403
|
+
added = false;
|
|
404
|
+
try {
|
|
405
|
+
for (_a = tslib_1.__values(this.entity.fields), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
406
|
+
x = _b.value;
|
|
407
|
+
if (e.isDbReadonly(x)) { }
|
|
408
|
+
else {
|
|
409
|
+
v = x.valueConverter.toDb(data[x.key]);
|
|
410
|
+
if (v != undefined) {
|
|
411
|
+
if (!added)
|
|
412
|
+
added = true;
|
|
413
|
+
else {
|
|
414
|
+
cols += ', ';
|
|
415
|
+
vals += ', ';
|
|
416
|
+
}
|
|
417
|
+
cols += e.nameOf(x);
|
|
418
|
+
vals += r.addParameterAndReturnSqlToken(v);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
424
|
+
finally {
|
|
425
|
+
try {
|
|
426
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
427
|
+
}
|
|
428
|
+
finally { if (e_5) throw e_5.error; }
|
|
429
|
+
}
|
|
430
|
+
statement = "insert into " + e.entityName + " (" + cols + ") values (" + vals + ")";
|
|
431
|
+
_c = this.buildSelect(e), colKeys = _c.colKeys, select = _c.select;
|
|
432
|
+
statement += ' returning ' + select;
|
|
433
|
+
return [4 /*yield*/, r.execute(statement).then(function (sql) { return _this.buildResultRow(colKeys, sql.rows[0], sql); })];
|
|
434
|
+
case 2: return [2 /*return*/, _e.sent()];
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
};
|
|
439
|
+
ActualSQLServerDataProvider.LogToConsole = false;
|
|
440
|
+
return ActualSQLServerDataProvider;
|
|
441
|
+
}());
|