remult 0.14.3 → 0.14.6
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 +1 -5
- package/classType.js +1 -2
- package/graphql.js +84 -146
- package/index.d.ts +1 -1
- package/index.js +25 -71
- package/inputTypes.js +9 -16
- package/package.json +2 -1
- package/postgres/index.js +1 -4
- package/postgres/postgres-data-provider.js +165 -364
- package/postgres/postgresColumnSyntax.js +4 -8
- package/remult-express.js +6 -10
- package/remult-knex/index.js +300 -720
- package/remult-middleware.js +24 -30
- package/remult-mongo.js +172 -406
- package/server/JsonEntityFileStorage.js +10 -15
- package/server/expressBridge.js +383 -569
- package/server/index.js +4 -11
- package/server/register-actions-on-server.js +12 -38
- package/server/register-entities-on-server.js +9 -13
- package/src/__EntityValueProvider.js +1 -2
- package/src/__RowsOfDataForTesting.js +1 -2
- package/src/backend-tests/backend-database-test-setup.backend-spec.js +72 -190
- package/src/backend-tests/my-test.backend-spec.js +45 -114
- package/src/column-interfaces.js +2 -6
- package/src/column.js +71 -113
- package/src/context.js +174 -330
- package/src/data-api.js +162 -326
- package/src/data-interfaces.js +7 -11
- package/src/data-providers/array-entity-data-provider.js +171 -286
- package/src/data-providers/in-memory-database.js +12 -27
- package/src/data-providers/json-data-provider.js +41 -77
- package/src/data-providers/rest-data-provider.js +102 -189
- package/src/data-providers/sql-database.js +223 -403
- package/src/data-providers/web-sql-data-provider.js +78 -139
- package/src/entity.js +1 -2
- package/src/filter/filter-consumer-bridge-to-sql-request.js +106 -248
- package/src/filter/filter-consumer-bridge-to-url-builder.js +1 -2
- package/src/filter/filter-interfaces.js +277 -440
- package/src/id-entity.js +8 -17
- package/src/remult3/RepositoryImplementation.js +1191 -2367
- package/src/remult3/index.js +2 -5
- package/src/remult3/remult3.js +1 -2
- package/src/server-action.js +294 -528
- package/src/shared-tests/db-tests-setup.js +49 -153
- package/src/shared-tests/db-tests.db-tests.js +660 -1566
- package/src/shared-tests/deleteAll.js +3 -20
- package/src/shared-tests/entityWithValidations.js +52 -79
- package/src/shared-tests/index.js +4 -6
- package/src/shared-tests/test-custom-id-column.spec.js +37 -85
- package/src/shared-tests/test-special-value.spec.js +64 -104
- package/src/shared-tests/test-update-with-null.spec.js +28 -49
- package/src/sort.js +38 -95
- package/src/sql-command.js +1 -2
- package/src/tests/Done.js +7 -13
- package/src/tests/TestDataApiResponse.js +15 -22
- package/src/tests/c.js +21 -27
- package/src/tests/createData.js +20 -48
- package/src/tests/d.js +19 -27
- package/src/tests/dWithPrefilter.js +31 -44
- package/src/tests/entityForCustomFilter.js +42 -66
- package/src/tests/entityWithValidationsOnColumn.js +21 -29
- package/src/tests/frontend-database-tests-setup.spec.js +35 -98
- package/src/tests/h.js +35 -44
- package/src/tests/remult-3-entities.js +71 -80
- package/src/tests/tasks.js +23 -29
- package/src/tests/testHelper.spec.js +170 -322
- package/src/tests/testModel/models.js +25 -33
- package/src/validators.js +32 -59
- package/urlBuilder.js +8 -14
- package/valueConverters.js +161 -160
|
@@ -1,283 +1,173 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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");
|
|
1
|
+
import { CompoundIdField } from "../column";
|
|
2
|
+
import { FilterConsumerBridgeToSqlRequest, getDbNameProvider } from "../filter/filter-consumer-bridge-to-sql-request";
|
|
3
|
+
import { customDatabaseFilterToken, Filter } from '../filter/filter-interfaces';
|
|
4
|
+
import { Sort } from '../sort';
|
|
9
5
|
// @dynamic
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
export class SqlDatabase {
|
|
7
|
+
constructor(sql) {
|
|
12
8
|
this.sql = sql;
|
|
13
9
|
this.createdEntities = [];
|
|
14
10
|
}
|
|
15
|
-
|
|
11
|
+
createCommand() {
|
|
16
12
|
return new LogSQLCommand(this.sql.createCommand(), SqlDatabase.LogToConsole);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
}
|
|
14
|
+
async execute(sql) {
|
|
15
|
+
return await this.createCommand().execute(sql);
|
|
16
|
+
}
|
|
17
|
+
getEntityDataProvider(entity) {
|
|
18
|
+
return new ActualSQLServerDataProvider(entity, this, async (dbName) => {
|
|
19
|
+
if (this.createdEntities.indexOf(dbName.entityName) < 0) {
|
|
20
|
+
this.createdEntities.push(dbName.entityName);
|
|
21
|
+
await this.sql.entityIsUsedForTheFirstTime(entity);
|
|
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
|
+
}
|
|
26
49
|
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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] = {
|
|
50
|
+
}
|
|
51
|
+
static customFilter(build) {
|
|
52
|
+
return {
|
|
53
|
+
[customDatabaseFilterToken]: {
|
|
90
54
|
buildSql: build
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
var LogSQLCommand = /** @class */ (function () {
|
|
100
|
-
function LogSQLCommand(origin, allQueries) {
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
SqlDatabase.LogToConsole = false;
|
|
60
|
+
SqlDatabase.durationThreshold = 0;
|
|
61
|
+
class LogSQLCommand {
|
|
62
|
+
constructor(origin, allQueries) {
|
|
101
63
|
this.origin = origin;
|
|
102
64
|
this.allQueries = allQueries;
|
|
103
65
|
this.args = {};
|
|
104
66
|
}
|
|
105
|
-
|
|
106
|
-
|
|
67
|
+
addParameterAndReturnSqlToken(val) {
|
|
68
|
+
let r = this.origin.addParameterAndReturnSqlToken(val);
|
|
107
69
|
this.args[r] = val;
|
|
108
70
|
return r;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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*/];
|
|
71
|
+
}
|
|
72
|
+
async execute(sql) {
|
|
73
|
+
try {
|
|
74
|
+
let start = new Date();
|
|
75
|
+
let r = await this.origin.execute(sql);
|
|
76
|
+
if (this.allQueries) {
|
|
77
|
+
var d = new Date().valueOf() - start.valueOf();
|
|
78
|
+
if (d > SqlDatabase.durationThreshold) {
|
|
79
|
+
console.log({ query: sql, arguments: this.args, duration: d / 1000 });
|
|
133
80
|
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
81
|
+
}
|
|
82
|
+
return r;
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
console.error({ error: err, query: sql, arguments: this.args });
|
|
86
|
+
throw err;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
class ActualSQLServerDataProvider {
|
|
91
|
+
constructor(entity, sql, iAmUsed, strategy) {
|
|
141
92
|
this.entity = entity;
|
|
142
93
|
this.sql = sql;
|
|
143
94
|
this.iAmUsed = iAmUsed;
|
|
144
95
|
this.strategy = strategy;
|
|
145
96
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
97
|
+
async init() {
|
|
98
|
+
let dbNameProvider = await getDbNameProvider(this.entity);
|
|
99
|
+
await this.iAmUsed(dbNameProvider);
|
|
100
|
+
return dbNameProvider;
|
|
101
|
+
}
|
|
102
|
+
async count(where) {
|
|
103
|
+
let e = await this.init();
|
|
104
|
+
let select = 'select count(*) count from ' + e.entityName;
|
|
105
|
+
let r = this.sql.createCommand();
|
|
106
|
+
if (where) {
|
|
107
|
+
let wc = new FilterConsumerBridgeToSqlRequest(r, e);
|
|
108
|
+
where.__applyToConsumer(wc);
|
|
109
|
+
select += await wc.resolveWhere();
|
|
110
|
+
}
|
|
111
|
+
return r.execute(select).then(r => {
|
|
112
|
+
return +r.rows[0].count;
|
|
160
113
|
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
})
|
|
114
|
+
}
|
|
115
|
+
async find(options) {
|
|
116
|
+
let e = await this.init();
|
|
117
|
+
let { colKeys, select } = this.buildSelect(e);
|
|
118
|
+
select = 'select ' + select;
|
|
119
|
+
select += '\n from ' + e.entityName;
|
|
120
|
+
let r = this.sql.createCommand();
|
|
121
|
+
if (options) {
|
|
122
|
+
if (options.where) {
|
|
123
|
+
let where = new FilterConsumerBridgeToSqlRequest(r, e);
|
|
124
|
+
options.where.__applyToConsumer(where);
|
|
125
|
+
select += await where.resolveWhere();
|
|
126
|
+
}
|
|
127
|
+
if (options.limit) {
|
|
128
|
+
options.orderBy = Sort.createUniqueSort(this.entity, options.orderBy);
|
|
129
|
+
}
|
|
130
|
+
if (options.orderBy) {
|
|
131
|
+
let first = true;
|
|
132
|
+
let segs = [];
|
|
133
|
+
for (const s of options.orderBy.Segments) {
|
|
134
|
+
if (s.field instanceof CompoundIdField) {
|
|
135
|
+
segs.push(...s.field.fields.map(c => ({ field: c, isDescending: s.isDescending })));
|
|
136
|
+
}
|
|
137
|
+
else
|
|
138
|
+
segs.push(s);
|
|
183
139
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
})];
|
|
140
|
+
for (const c of segs) {
|
|
141
|
+
if (first) {
|
|
142
|
+
select += ' Order By ';
|
|
143
|
+
first = false;
|
|
144
|
+
}
|
|
145
|
+
else
|
|
146
|
+
select += ', ';
|
|
147
|
+
select += e.nameOf(c.field);
|
|
148
|
+
if (c.isDescending)
|
|
149
|
+
select += ' desc';
|
|
273
150
|
}
|
|
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);
|
|
274
164
|
});
|
|
275
165
|
});
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
for (
|
|
280
|
-
|
|
166
|
+
}
|
|
167
|
+
buildResultRow(colKeys, y, r) {
|
|
168
|
+
let result = {};
|
|
169
|
+
for (let index = 0; index < colKeys.length; index++) {
|
|
170
|
+
const col = colKeys[index];
|
|
281
171
|
try {
|
|
282
172
|
result[col.key] = col.valueConverter.fromDb(y[r.getColumnKeyInResultForIndexInSelect(index)]);
|
|
283
173
|
}
|
|
@@ -286,156 +176,86 @@ var ActualSQLServerDataProvider = /** @class */ (function () {
|
|
|
286
176
|
}
|
|
287
177
|
}
|
|
288
178
|
return result;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
}
|
|
179
|
+
}
|
|
180
|
+
buildSelect(e) {
|
|
181
|
+
let select = '';
|
|
182
|
+
let colKeys = [];
|
|
183
|
+
for (const x of this.entity.fields) {
|
|
184
|
+
if (x.isServerExpression) {
|
|
305
185
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
186
|
+
else {
|
|
187
|
+
if (colKeys.length > 0)
|
|
188
|
+
select += ', ';
|
|
189
|
+
select += e.nameOf(x);
|
|
190
|
+
colKeys.push(x);
|
|
311
191
|
}
|
|
312
|
-
finally { if (e_3) throw e_3.error; }
|
|
313
192
|
}
|
|
314
|
-
return { colKeys
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
});
|
|
367
|
-
});
|
|
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 () { })];
|
|
193
|
+
return { colKeys, select };
|
|
194
|
+
}
|
|
195
|
+
async update(id, data) {
|
|
196
|
+
let e = await this.init();
|
|
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);
|
|
386
214
|
}
|
|
387
|
-
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
statement += await f.resolveWhere();
|
|
218
|
+
let { colKeys, select } = this.buildSelect(e);
|
|
219
|
+
statement += ' returning ' + select;
|
|
220
|
+
return r.execute(statement).then(sqlResult => {
|
|
221
|
+
return this.buildResultRow(colKeys, sqlResult.rows[0], sqlResult);
|
|
388
222
|
});
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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()];
|
|
223
|
+
}
|
|
224
|
+
async delete(id) {
|
|
225
|
+
let e = await this.init();
|
|
226
|
+
let r = this.sql.createCommand();
|
|
227
|
+
let f = new FilterConsumerBridgeToSqlRequest(r, e);
|
|
228
|
+
Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
229
|
+
let statement = 'delete from ' + e.entityName;
|
|
230
|
+
statement += await f.resolveWhere();
|
|
231
|
+
return r.execute(statement).then(() => { });
|
|
232
|
+
}
|
|
233
|
+
async insert(data) {
|
|
234
|
+
let e = await this.init();
|
|
235
|
+
let r = this.sql.createCommand();
|
|
236
|
+
let cols = '';
|
|
237
|
+
let vals = '';
|
|
238
|
+
let added = false;
|
|
239
|
+
for (const x of this.entity.fields) {
|
|
240
|
+
if (e.isDbReadonly(x)) { }
|
|
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);
|
|
435
252
|
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
let statement = `insert into ${e.entityName} (${cols}) values (${vals})`;
|
|
256
|
+
let { colKeys, select } = this.buildSelect(e);
|
|
257
|
+
statement += ' returning ' + select;
|
|
258
|
+
return await r.execute(statement).then(sql => this.buildResultRow(colKeys, sql.rows[0], sql));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
ActualSQLServerDataProvider.LogToConsole = false;
|