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,194 +1,393 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPostgresConnection = exports.preparePostgresQueueStorage = exports.PostgresSchemaBuilder = exports.verifyStructureOfAllEntities = exports.PostgresDataProvider = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var pg_1 = require("pg");
|
|
6
|
+
var context_1 = require("../src/context");
|
|
7
|
+
var postgresColumnSyntax_1 = require("./postgresColumnSyntax");
|
|
8
|
+
var filter_consumer_bridge_to_sql_request_1 = require("../src/filter/filter-consumer-bridge-to-sql-request");
|
|
9
|
+
var remult3_1 = require("../src/remult3");
|
|
10
|
+
var sql_database_1 = require("../src/data-providers/sql-database");
|
|
11
|
+
var PostgresDataProvider = /** @class */ (function () {
|
|
12
|
+
function PostgresDataProvider(pool) {
|
|
9
13
|
this.pool = pool;
|
|
10
14
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
PostgresDataProvider.prototype.entityIsUsedForTheFirstTime = function (entity) {
|
|
16
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
17
|
+
return tslib_1.__generator(this, function (_a) {
|
|
18
|
+
return [2 /*return*/];
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
PostgresDataProvider.prototype.getLimitSqlSyntax = function (limit, offset) {
|
|
14
23
|
return ' limit ' + limit + ' offset ' + offset;
|
|
15
|
-
}
|
|
16
|
-
createCommand() {
|
|
24
|
+
};
|
|
25
|
+
PostgresDataProvider.prototype.createCommand = function () {
|
|
17
26
|
return new PostgresBridgeToSQLCommand(this.pool);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
};
|
|
28
|
+
PostgresDataProvider.prototype.transaction = function (action) {
|
|
29
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
30
|
+
var client, err_1;
|
|
31
|
+
return tslib_1.__generator(this, function (_a) {
|
|
32
|
+
switch (_a.label) {
|
|
33
|
+
case 0: return [4 /*yield*/, this.pool.connect()];
|
|
34
|
+
case 1:
|
|
35
|
+
client = _a.sent();
|
|
36
|
+
_a.label = 2;
|
|
37
|
+
case 2:
|
|
38
|
+
_a.trys.push([2, 6, 8, 10]);
|
|
39
|
+
return [4 /*yield*/, client.query('BEGIN')];
|
|
40
|
+
case 3:
|
|
41
|
+
_a.sent();
|
|
42
|
+
return [4 /*yield*/, action({
|
|
43
|
+
createCommand: function () { return new PostgresBridgeToSQLCommand(client); },
|
|
44
|
+
entityIsUsedForTheFirstTime: this.entityIsUsedForTheFirstTime,
|
|
45
|
+
transaction: function () { throw "nested transactions not allowed"; },
|
|
46
|
+
getLimitSqlSyntax: this.getLimitSqlSyntax
|
|
47
|
+
})];
|
|
48
|
+
case 4:
|
|
49
|
+
_a.sent();
|
|
50
|
+
return [4 /*yield*/, client.query('COMMIT')];
|
|
51
|
+
case 5:
|
|
52
|
+
_a.sent();
|
|
53
|
+
return [3 /*break*/, 10];
|
|
54
|
+
case 6:
|
|
55
|
+
err_1 = _a.sent();
|
|
56
|
+
return [4 /*yield*/, client.query('ROLLBACK')];
|
|
57
|
+
case 7:
|
|
58
|
+
_a.sent();
|
|
59
|
+
throw err_1;
|
|
60
|
+
case 8: return [4 /*yield*/, client.release()];
|
|
61
|
+
case 9:
|
|
62
|
+
_a.sent();
|
|
63
|
+
return [7 /*endfinally*/];
|
|
64
|
+
case 10: return [2 /*return*/];
|
|
65
|
+
}
|
|
28
66
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
await client.release();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
class PostgresBridgeToSQLCommand {
|
|
41
|
-
constructor(source) {
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
return PostgresDataProvider;
|
|
70
|
+
}());
|
|
71
|
+
exports.PostgresDataProvider = PostgresDataProvider;
|
|
72
|
+
var PostgresBridgeToSQLCommand = /** @class */ (function () {
|
|
73
|
+
function PostgresBridgeToSQLCommand(source) {
|
|
42
74
|
this.source = source;
|
|
43
75
|
this.values = [];
|
|
44
76
|
}
|
|
45
|
-
addParameterAndReturnSqlToken(val) {
|
|
77
|
+
PostgresBridgeToSQLCommand.prototype.addParameterAndReturnSqlToken = function (val) {
|
|
46
78
|
this.values.push(val);
|
|
47
79
|
return '$' + this.values.length;
|
|
48
|
-
}
|
|
49
|
-
execute(sql) {
|
|
50
|
-
return this.source.query(sql, this.values).then(r
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
80
|
+
};
|
|
81
|
+
PostgresBridgeToSQLCommand.prototype.execute = function (sql) {
|
|
82
|
+
return this.source.query(sql, this.values).then(function (r) { return new PostgresBridgeToSQLQueryResult(r); });
|
|
83
|
+
};
|
|
84
|
+
return PostgresBridgeToSQLCommand;
|
|
85
|
+
}());
|
|
86
|
+
var PostgresBridgeToSQLQueryResult = /** @class */ (function () {
|
|
87
|
+
function PostgresBridgeToSQLQueryResult(r) {
|
|
55
88
|
this.r = r;
|
|
56
89
|
this.rows = r.rows;
|
|
57
90
|
}
|
|
58
|
-
getColumnKeyInResultForIndexInSelect(index) {
|
|
91
|
+
PostgresBridgeToSQLQueryResult.prototype.getColumnKeyInResultForIndexInSelect = function (index) {
|
|
59
92
|
return this.r.fields[index].name;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
93
|
+
};
|
|
94
|
+
return PostgresBridgeToSQLQueryResult;
|
|
95
|
+
}());
|
|
96
|
+
function verifyStructureOfAllEntities(db, remult) {
|
|
97
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
98
|
+
return tslib_1.__generator(this, function (_a) {
|
|
99
|
+
switch (_a.label) {
|
|
100
|
+
case 0: return [4 /*yield*/, new PostgresSchemaBuilder(db).verifyStructureOfAllEntities(remult)];
|
|
101
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
64
105
|
}
|
|
65
|
-
|
|
66
|
-
|
|
106
|
+
exports.verifyStructureOfAllEntities = verifyStructureOfAllEntities;
|
|
107
|
+
var PostgresSchemaBuilder = /** @class */ (function () {
|
|
108
|
+
function PostgresSchemaBuilder(pool, schema) {
|
|
67
109
|
this.pool = pool;
|
|
68
110
|
this.additionalWhere = '';
|
|
69
111
|
if (schema) {
|
|
70
112
|
this.additionalWhere = ' and table_schema=\'' + schema + '\'';
|
|
71
113
|
}
|
|
72
114
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
115
|
+
PostgresSchemaBuilder.prototype.verifyStructureOfAllEntities = function (remult) {
|
|
116
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
117
|
+
var allEntities_1, allEntities_1_1, entityClass, entity, e, err_2, e_1_1;
|
|
118
|
+
var e_1, _a;
|
|
119
|
+
return tslib_1.__generator(this, function (_b) {
|
|
120
|
+
switch (_b.label) {
|
|
121
|
+
case 0:
|
|
122
|
+
console.log("start verify structure");
|
|
123
|
+
_b.label = 1;
|
|
124
|
+
case 1:
|
|
125
|
+
_b.trys.push([1, 12, 13, 14]);
|
|
126
|
+
allEntities_1 = tslib_1.__values(context_1.allEntities), allEntities_1_1 = allEntities_1.next();
|
|
127
|
+
_b.label = 2;
|
|
128
|
+
case 2:
|
|
129
|
+
if (!!allEntities_1_1.done) return [3 /*break*/, 11];
|
|
130
|
+
entityClass = allEntities_1_1.value;
|
|
131
|
+
entity = remult.repo(entityClass).metadata;
|
|
132
|
+
return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.getDbNameProvider(entity)];
|
|
133
|
+
case 3:
|
|
134
|
+
e = _b.sent();
|
|
135
|
+
_b.label = 4;
|
|
136
|
+
case 4:
|
|
137
|
+
_b.trys.push([4, 9, , 10]);
|
|
138
|
+
if (!!entity.options.sqlExpression) return [3 /*break*/, 8];
|
|
139
|
+
return [4 /*yield*/, e.entityName];
|
|
140
|
+
case 5:
|
|
141
|
+
if (!((_b.sent()).toLowerCase().indexOf('from ') < 0)) return [3 /*break*/, 8];
|
|
142
|
+
return [4 /*yield*/, this.createIfNotExist(entity)];
|
|
143
|
+
case 6:
|
|
144
|
+
_b.sent();
|
|
145
|
+
return [4 /*yield*/, this.verifyAllColumns(entity)];
|
|
146
|
+
case 7:
|
|
147
|
+
_b.sent();
|
|
148
|
+
_b.label = 8;
|
|
149
|
+
case 8: return [3 /*break*/, 10];
|
|
150
|
+
case 9:
|
|
151
|
+
err_2 = _b.sent();
|
|
152
|
+
console.log("failed verify structure of " + e.entityName + " ", err_2);
|
|
153
|
+
return [3 /*break*/, 10];
|
|
154
|
+
case 10:
|
|
155
|
+
allEntities_1_1 = allEntities_1.next();
|
|
156
|
+
return [3 /*break*/, 2];
|
|
157
|
+
case 11: return [3 /*break*/, 14];
|
|
158
|
+
case 12:
|
|
159
|
+
e_1_1 = _b.sent();
|
|
160
|
+
e_1 = { error: e_1_1 };
|
|
161
|
+
return [3 /*break*/, 14];
|
|
162
|
+
case 13:
|
|
163
|
+
try {
|
|
164
|
+
if (allEntities_1_1 && !allEntities_1_1.done && (_a = allEntities_1.return)) _a.call(allEntities_1);
|
|
165
|
+
}
|
|
166
|
+
finally { if (e_1) throw e_1.error; }
|
|
167
|
+
return [7 /*endfinally*/];
|
|
168
|
+
case 14: return [2 /*return*/];
|
|
84
169
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
PostgresSchemaBuilder.prototype.createIfNotExist = function (entity) {
|
|
174
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
175
|
+
var c, e;
|
|
176
|
+
var _this = this;
|
|
177
|
+
return tslib_1.__generator(this, function (_a) {
|
|
178
|
+
switch (_a.label) {
|
|
179
|
+
case 0:
|
|
180
|
+
c = this.pool.createCommand();
|
|
181
|
+
return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.getDbNameProvider(entity)];
|
|
182
|
+
case 1:
|
|
183
|
+
e = _a.sent();
|
|
184
|
+
return [4 /*yield*/, c.execute("select 1 from information_Schema.tables where table_name=" + c.addParameterAndReturnSqlToken((e.entityName).toLowerCase()) + this.additionalWhere).then(function (r) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
185
|
+
var result, _a, _b, x, sql;
|
|
186
|
+
var e_2, _c;
|
|
187
|
+
return tslib_1.__generator(this, function (_d) {
|
|
188
|
+
switch (_d.label) {
|
|
189
|
+
case 0:
|
|
190
|
+
if (!(r.rows.length == 0)) return [3 /*break*/, 2];
|
|
191
|
+
result = '';
|
|
192
|
+
try {
|
|
193
|
+
for (_a = tslib_1.__values(entity.fields), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
194
|
+
x = _b.value;
|
|
195
|
+
if (!e.isDbReadonly(x) || remult3_1.isAutoIncrement(x)) {
|
|
196
|
+
if (result.length != 0)
|
|
197
|
+
result += ',';
|
|
198
|
+
result += '\r\n ';
|
|
199
|
+
if (remult3_1.isAutoIncrement(x))
|
|
200
|
+
result += e.nameOf(x) + ' serial';
|
|
201
|
+
else {
|
|
202
|
+
result += postgresColumnSyntax_1.postgresColumnSyntax(x, e.nameOf(x));
|
|
203
|
+
if (x == entity.idMetadata.field)
|
|
204
|
+
result += ' primary key';
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
210
|
+
finally {
|
|
211
|
+
try {
|
|
212
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
213
|
+
}
|
|
214
|
+
finally { if (e_2) throw e_2.error; }
|
|
215
|
+
}
|
|
216
|
+
sql = 'create table ' + e.entityName + ' (' + result + '\r\n)';
|
|
217
|
+
//console.log(sql);
|
|
218
|
+
return [4 /*yield*/, this.pool.execute(sql)];
|
|
219
|
+
case 1:
|
|
220
|
+
//console.log(sql);
|
|
221
|
+
_d.sent();
|
|
222
|
+
_d.label = 2;
|
|
223
|
+
case 2: return [2 /*return*/];
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}); })];
|
|
227
|
+
case 2:
|
|
228
|
+
_a.sent();
|
|
229
|
+
return [2 /*return*/];
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
PostgresSchemaBuilder.prototype.addColumnIfNotExist = function (entity, c) {
|
|
235
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
236
|
+
var e, cmd, colName, sql, err_3;
|
|
237
|
+
return tslib_1.__generator(this, function (_a) {
|
|
238
|
+
switch (_a.label) {
|
|
239
|
+
case 0: return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.getDbNameProvider(entity)];
|
|
240
|
+
case 1:
|
|
241
|
+
e = _a.sent();
|
|
242
|
+
if (e.isDbReadonly(c(entity)))
|
|
243
|
+
return [2 /*return*/];
|
|
244
|
+
_a.label = 2;
|
|
245
|
+
case 2:
|
|
246
|
+
_a.trys.push([2, 6, , 7]);
|
|
247
|
+
cmd = this.pool.createCommand();
|
|
248
|
+
colName = e.nameOf(c(entity));
|
|
249
|
+
return [4 /*yield*/, cmd.execute("select 1 \n FROM information_schema.columns \n WHERE table_name=" + cmd.addParameterAndReturnSqlToken((e.entityName).toLocaleLowerCase()) + " and column_name=" + cmd.addParameterAndReturnSqlToken((colName).toLocaleLowerCase()) + this.additionalWhere)];
|
|
250
|
+
case 3:
|
|
251
|
+
if (!((_a.sent()).rows.length == 0)) return [3 /*break*/, 5];
|
|
252
|
+
sql = "alter table " + e.entityName + " add column " + postgresColumnSyntax_1.postgresColumnSyntax(c(entity), colName);
|
|
253
|
+
//console.log(sql);
|
|
254
|
+
return [4 /*yield*/, this.pool.execute(sql)];
|
|
255
|
+
case 4:
|
|
256
|
+
//console.log(sql);
|
|
257
|
+
_a.sent();
|
|
258
|
+
_a.label = 5;
|
|
259
|
+
case 5: return [3 /*break*/, 7];
|
|
260
|
+
case 6:
|
|
261
|
+
err_3 = _a.sent();
|
|
262
|
+
console.log(err_3);
|
|
263
|
+
return [3 /*break*/, 7];
|
|
264
|
+
case 7: return [2 /*return*/];
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
PostgresSchemaBuilder.prototype.verifyAllColumns = function (entity) {
|
|
270
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
271
|
+
var cmd, e, cols, _a, _b, col, sql, e_3_1, err_4;
|
|
272
|
+
var e_3, _c;
|
|
273
|
+
return tslib_1.__generator(this, function (_d) {
|
|
274
|
+
switch (_d.label) {
|
|
275
|
+
case 0:
|
|
276
|
+
_d.trys.push([0, 11, , 12]);
|
|
277
|
+
cmd = this.pool.createCommand();
|
|
278
|
+
return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.getDbNameProvider(entity)];
|
|
279
|
+
case 1:
|
|
280
|
+
e = _d.sent();
|
|
281
|
+
return [4 /*yield*/, cmd.execute("select column_name \n FROM information_schema.columns \n WHERE table_name=" + cmd.addParameterAndReturnSqlToken((e.entityName).toLocaleLowerCase()) + " " + this.additionalWhere)];
|
|
282
|
+
case 2:
|
|
283
|
+
cols = (_d.sent()).rows.map(function (x) { return x.column_name; });
|
|
284
|
+
_d.label = 3;
|
|
285
|
+
case 3:
|
|
286
|
+
_d.trys.push([3, 8, 9, 10]);
|
|
287
|
+
_a = tslib_1.__values(entity.fields), _b = _a.next();
|
|
288
|
+
_d.label = 4;
|
|
289
|
+
case 4:
|
|
290
|
+
if (!!_b.done) return [3 /*break*/, 7];
|
|
291
|
+
col = _b.value;
|
|
292
|
+
if (!!e.isDbReadonly(col)) return [3 /*break*/, 6];
|
|
293
|
+
if (!!cols.includes(e.nameOf(col).toLocaleLowerCase())) return [3 /*break*/, 6];
|
|
294
|
+
sql = "alter table " + e.entityName + " add column " + postgresColumnSyntax_1.postgresColumnSyntax(col, e.nameOf(col));
|
|
295
|
+
//console.log(sql);
|
|
296
|
+
return [4 /*yield*/, this.pool.execute(sql)];
|
|
297
|
+
case 5:
|
|
298
|
+
//console.log(sql);
|
|
299
|
+
_d.sent();
|
|
300
|
+
_d.label = 6;
|
|
301
|
+
case 6:
|
|
302
|
+
_b = _a.next();
|
|
303
|
+
return [3 /*break*/, 4];
|
|
304
|
+
case 7: return [3 /*break*/, 10];
|
|
305
|
+
case 8:
|
|
306
|
+
e_3_1 = _d.sent();
|
|
307
|
+
e_3 = { error: e_3_1 };
|
|
308
|
+
return [3 /*break*/, 10];
|
|
309
|
+
case 9:
|
|
310
|
+
try {
|
|
311
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
108
312
|
}
|
|
109
|
-
|
|
313
|
+
finally { if (e_3) throw e_3.error; }
|
|
314
|
+
return [7 /*endfinally*/];
|
|
315
|
+
case 10: return [3 /*break*/, 12];
|
|
316
|
+
case 11:
|
|
317
|
+
err_4 = _d.sent();
|
|
318
|
+
console.log(err_4);
|
|
319
|
+
return [3 /*break*/, 12];
|
|
320
|
+
case 12: return [2 /*return*/];
|
|
110
321
|
}
|
|
111
|
-
|
|
112
|
-
//console.log(sql);
|
|
113
|
-
await this.pool.execute(sql);
|
|
114
|
-
}
|
|
322
|
+
});
|
|
115
323
|
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
324
|
+
};
|
|
325
|
+
return PostgresSchemaBuilder;
|
|
326
|
+
}());
|
|
327
|
+
exports.PostgresSchemaBuilder = PostgresSchemaBuilder;
|
|
328
|
+
function preparePostgresQueueStorage(sql) {
|
|
329
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
330
|
+
var c, JobsInQueueEntity, e;
|
|
331
|
+
return tslib_1.__generator(this, function (_a) {
|
|
332
|
+
switch (_a.label) {
|
|
333
|
+
case 0:
|
|
334
|
+
c = new context_1.Remult();
|
|
335
|
+
c.setDataProvider(sql);
|
|
336
|
+
return [4 /*yield*/, Promise.resolve().then(function () { return require('../server/expressBridge'); })];
|
|
337
|
+
case 1:
|
|
338
|
+
JobsInQueueEntity = (_a.sent()).JobsInQueueEntity;
|
|
339
|
+
e = c.repo(JobsInQueueEntity);
|
|
340
|
+
return [4 /*yield*/, new PostgresSchemaBuilder(sql).createIfNotExist(e.metadata)];
|
|
341
|
+
case 2:
|
|
342
|
+
_a.sent();
|
|
343
|
+
return [4 /*yield*/, new PostgresSchemaBuilder(sql).verifyAllColumns(e.metadata)];
|
|
344
|
+
case 3:
|
|
345
|
+
_a.sent();
|
|
346
|
+
return [4 /*yield*/, Promise.resolve().then(function () { return require('../server/expressBridge'); })];
|
|
347
|
+
case 4: return [2 /*return*/, new (_a.sent()).EntityQueueStorage(c.repo(JobsInQueueEntity))];
|
|
130
348
|
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
exports.preparePostgresQueueStorage = preparePostgresQueueStorage;
|
|
353
|
+
function createPostgresConnection(options) {
|
|
354
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
355
|
+
var config, db, remult;
|
|
356
|
+
return tslib_1.__generator(this, function (_a) {
|
|
357
|
+
switch (_a.label) {
|
|
358
|
+
case 0:
|
|
359
|
+
if (!options)
|
|
360
|
+
options = {};
|
|
361
|
+
config = {};
|
|
362
|
+
if (options.configuration)
|
|
363
|
+
if (options.configuration == "heroku") {
|
|
364
|
+
config = {
|
|
365
|
+
connectionString: process.env.DATABASE_URL,
|
|
366
|
+
ssl: process.env.NODE_ENV !== "production" && !options.sslInDev ? false : {
|
|
367
|
+
rejectUnauthorized: false
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
else
|
|
372
|
+
config = options.configuration;
|
|
373
|
+
else {
|
|
374
|
+
if (!options.connectionString)
|
|
375
|
+
options.connectionString = process.env.DATABASE_URL;
|
|
376
|
+
}
|
|
377
|
+
if (!config.connectionString && options.connectionString) {
|
|
378
|
+
config.connectionString = options.connectionString;
|
|
149
379
|
}
|
|
380
|
+
db = new sql_database_1.SqlDatabase(new PostgresDataProvider(new pg_1.Pool(config)));
|
|
381
|
+
remult = new context_1.Remult();
|
|
382
|
+
remult.setDataProvider(db);
|
|
383
|
+
if (!(options.autoCreateTables === undefined || options.autoCreateTables)) return [3 /*break*/, 2];
|
|
384
|
+
return [4 /*yield*/, verifyStructureOfAllEntities(db, remult)];
|
|
385
|
+
case 1:
|
|
386
|
+
_a.sent();
|
|
387
|
+
_a.label = 2;
|
|
388
|
+
case 2: return [2 /*return*/, db];
|
|
150
389
|
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
console.log(err);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
export async function preparePostgresQueueStorage(sql) {
|
|
158
|
-
let c = new Remult();
|
|
159
|
-
c.setDataProvider(sql);
|
|
160
|
-
let JobsInQueueEntity = (await import('../server/expressBridge')).JobsInQueueEntity;
|
|
161
|
-
let e = c.repo(JobsInQueueEntity);
|
|
162
|
-
await new PostgresSchemaBuilder(sql).createIfNotExist(e.metadata);
|
|
163
|
-
await new PostgresSchemaBuilder(sql).verifyAllColumns(e.metadata);
|
|
164
|
-
return new (await import('../server/expressBridge')).EntityQueueStorage(c.repo(JobsInQueueEntity));
|
|
165
|
-
}
|
|
166
|
-
export async function createPostgresConnection(options) {
|
|
167
|
-
if (!options)
|
|
168
|
-
options = {};
|
|
169
|
-
let config = {};
|
|
170
|
-
if (options.configuration)
|
|
171
|
-
if (options.configuration == "heroku") {
|
|
172
|
-
config = {
|
|
173
|
-
connectionString: process.env.DATABASE_URL,
|
|
174
|
-
ssl: process.env.NODE_ENV !== "production" && !options.sslInDev ? false : {
|
|
175
|
-
rejectUnauthorized: false
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
else
|
|
180
|
-
config = options.configuration;
|
|
181
|
-
else {
|
|
182
|
-
if (!options.connectionString)
|
|
183
|
-
options.connectionString = process.env.DATABASE_URL;
|
|
184
|
-
}
|
|
185
|
-
if (!config.connectionString && options.connectionString) {
|
|
186
|
-
config.connectionString = options.connectionString;
|
|
187
|
-
}
|
|
188
|
-
const db = new SqlDatabase(new PostgresDataProvider(new Pool(config)));
|
|
189
|
-
let remult = new Remult();
|
|
190
|
-
remult.setDataProvider(db);
|
|
191
|
-
if (options.autoCreateTables === undefined || options.autoCreateTables)
|
|
192
|
-
await verifyStructureOfAllEntities(db, remult);
|
|
193
|
-
return db;
|
|
390
|
+
});
|
|
391
|
+
});
|
|
194
392
|
}
|
|
393
|
+
exports.createPostgresConnection = createPostgresConnection;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FieldMetadata } from '../';
|
|
1
|
+
import { FieldMetadata } from '../src/column-interfaces';
|
|
2
2
|
export declare function postgresColumnSyntax(x: FieldMetadata, dbName: string): string;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.postgresColumnSyntax = void 0;
|
|
4
|
+
var valueConverters_1 = require("../valueConverters");
|
|
5
|
+
function postgresColumnSyntax(x, dbName) {
|
|
6
|
+
var result = dbName;
|
|
4
7
|
if (x.valueType == Number) {
|
|
5
8
|
if (!x.valueConverter.fieldTypeInDb)
|
|
6
9
|
result += " numeric" + (x.allowNull ? "" : " default 0 not null");
|
|
@@ -9,7 +12,7 @@ export function postgresColumnSyntax(x, dbName) {
|
|
|
9
12
|
}
|
|
10
13
|
else if (x.valueType == Date) {
|
|
11
14
|
if (!x.valueConverter.fieldTypeInDb)
|
|
12
|
-
if (x.valueConverter == ValueConverters.DateOnly)
|
|
15
|
+
if (x.valueConverter == valueConverters_1.ValueConverters.DateOnly)
|
|
13
16
|
result += " date";
|
|
14
17
|
else
|
|
15
18
|
result += " timestamp";
|
|
@@ -28,3 +31,4 @@ export function postgresColumnSyntax(x, dbName) {
|
|
|
28
31
|
result += " varchar" + (x.allowNull ? "" : " default '' not null");
|
|
29
32
|
return result;
|
|
30
33
|
}
|
|
34
|
+
exports.postgresColumnSyntax = postgresColumnSyntax;
|
package/remult-express.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.remultExpress = void 0;
|
|
4
|
+
var express = require("express");
|
|
5
|
+
var expressBridge_1 = require("./server/expressBridge");
|
|
6
|
+
function remultExpress(options) {
|
|
7
|
+
var app = express.Router();
|
|
5
8
|
if (!options) {
|
|
6
9
|
options = {};
|
|
7
10
|
}
|
|
8
11
|
if (options.bodySizeLimit === undefined) {
|
|
9
12
|
options.bodySizeLimit = '10mb';
|
|
10
13
|
}
|
|
11
|
-
if (options
|
|
14
|
+
if ((options === null || options === void 0 ? void 0 : options.bodyParser) !== false) {
|
|
12
15
|
app.use(express.json({ limit: options.bodySizeLimit }));
|
|
13
16
|
app.use(express.urlencoded({ extended: true, limit: options.bodySizeLimit }));
|
|
14
17
|
}
|
|
15
|
-
return remultMiddlewareBase(app, options);
|
|
18
|
+
return expressBridge_1.remultMiddlewareBase(app, options);
|
|
16
19
|
}
|
|
20
|
+
exports.remultExpress = remultExpress;
|
package/remult-knex/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { DataProvider, EntityDataProvider, EntityFilter, EntityMetadata, FieldMetadata, Filter, Remult } from "..";
|
|
2
1
|
import { Knex } from 'knex';
|
|
3
|
-
import { FilterConsumer } from "../src/filter/filter-interfaces";
|
|
2
|
+
import { Filter, FilterConsumer } from "../src/filter/filter-interfaces";
|
|
4
3
|
import { dbNameProvider } from "../src/filter/filter-consumer-bridge-to-sql-request";
|
|
4
|
+
import { Remult } from "../src/context";
|
|
5
|
+
import { EntityFilter, EntityMetadata } from "../src/remult3";
|
|
6
|
+
import { DataProvider, EntityDataProvider } from '../src/data-interfaces';
|
|
7
|
+
import { FieldMetadata } from '../src/column-interfaces';
|
|
5
8
|
export declare class KnexDataProvider implements DataProvider {
|
|
6
9
|
knex: Knex;
|
|
7
10
|
constructor(knex: Knex);
|