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,114 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var remult3_1 = require("../remult3");
|
|
6
|
-
var sql_database_1 = require("./sql-database");
|
|
7
|
-
var filter_consumer_bridge_to_sql_request_1 = require("../filter/filter-consumer-bridge-to-sql-request");
|
|
1
|
+
import { isAutoIncrement } from "../remult3";
|
|
2
|
+
import { SqlDatabase } from "./sql-database";
|
|
3
|
+
import { getDbNameProvider } from "../filter/filter-consumer-bridge-to-sql-request";
|
|
8
4
|
//SqlDatabase.LogToConsole = true;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (databaseSize === void 0) { databaseSize = 2 * 1024 * 1024; }
|
|
5
|
+
export class WebSqlDataProvider {
|
|
6
|
+
constructor(databaseName, databaseSize = 2 * 1024 * 1024) {
|
|
12
7
|
this.databaseName = databaseName;
|
|
13
8
|
//@ts-ignore
|
|
14
9
|
this.db = window.openDatabase(databaseName, '1.0', databaseName, databaseSize);
|
|
15
10
|
}
|
|
16
|
-
|
|
11
|
+
getLimitSqlSyntax(limit, offset) {
|
|
17
12
|
return ' limit ' + limit + ' offset ' + offset;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
sql
|
|
40
|
-
|
|
41
|
-
console.log(sql);
|
|
42
|
-
return [4 /*yield*/, this.createCommand().execute(sql)];
|
|
43
|
-
case 2:
|
|
44
|
-
_a.sent();
|
|
45
|
-
return [2 /*return*/];
|
|
13
|
+
}
|
|
14
|
+
async entityIsUsedForTheFirstTime(entity) {
|
|
15
|
+
await this.createTable(entity);
|
|
16
|
+
}
|
|
17
|
+
async dropTable(entity) {
|
|
18
|
+
let e = await getDbNameProvider(entity);
|
|
19
|
+
let sql = 'drop table if exists ' + e.entityName;
|
|
20
|
+
if (SqlDatabase.LogToConsole)
|
|
21
|
+
console.log(sql);
|
|
22
|
+
await this.createCommand().execute(sql);
|
|
23
|
+
}
|
|
24
|
+
async createTable(entity) {
|
|
25
|
+
let result = '';
|
|
26
|
+
let e = await getDbNameProvider(entity);
|
|
27
|
+
for (const x of entity.fields) {
|
|
28
|
+
if (!e.isDbReadonly(x) || isAutoIncrement(x)) {
|
|
29
|
+
if (result.length != 0)
|
|
30
|
+
result += ',';
|
|
31
|
+
result += '\r\n ';
|
|
32
|
+
if (isAutoIncrement(x)) {
|
|
33
|
+
if (x.key != entity.idMetadata.field.key)
|
|
34
|
+
throw "in web sql, autoincrement is only allowed for primary key";
|
|
35
|
+
result += e.nameOf(x) + ' integer primary key autoincrement';
|
|
46
36
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var result, e, _a, _b, x, sql;
|
|
53
|
-
var e_1, _c;
|
|
54
|
-
return tslib_1.__generator(this, function (_d) {
|
|
55
|
-
switch (_d.label) {
|
|
56
|
-
case 0:
|
|
57
|
-
result = '';
|
|
58
|
-
return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.getDbNameProvider(entity)];
|
|
59
|
-
case 1:
|
|
60
|
-
e = _d.sent();
|
|
61
|
-
try {
|
|
62
|
-
for (_a = tslib_1.__values(entity.fields), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
63
|
-
x = _b.value;
|
|
64
|
-
if (!e.isDbReadonly(x) || remult3_1.isAutoIncrement(x)) {
|
|
65
|
-
if (result.length != 0)
|
|
66
|
-
result += ',';
|
|
67
|
-
result += '\r\n ';
|
|
68
|
-
if (remult3_1.isAutoIncrement(x)) {
|
|
69
|
-
if (x.key != entity.idMetadata.field.key)
|
|
70
|
-
throw "in web sql, autoincrement is only allowed for primary key";
|
|
71
|
-
result += e.nameOf(x) + ' integer primary key autoincrement';
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
result += this.addColumnSqlSyntax(x, e.nameOf(x));
|
|
75
|
-
if (x.key == entity.idMetadata.field.key) {
|
|
76
|
-
result += ' primary key';
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
83
|
-
finally {
|
|
84
|
-
try {
|
|
85
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
86
|
-
}
|
|
87
|
-
finally { if (e_1) throw e_1.error; }
|
|
88
|
-
}
|
|
89
|
-
sql = 'create table if not exists ' + e.entityName + ' (' + result + '\r\n)';
|
|
90
|
-
if (sql_database_1.SqlDatabase.LogToConsole)
|
|
91
|
-
console.log(sql);
|
|
92
|
-
return [4 /*yield*/, this.createCommand().execute(sql)];
|
|
93
|
-
case 2:
|
|
94
|
-
_d.sent();
|
|
95
|
-
return [2 /*return*/];
|
|
37
|
+
else {
|
|
38
|
+
result += this.addColumnSqlSyntax(x, e.nameOf(x));
|
|
39
|
+
if (x.key == entity.idMetadata.field.key) {
|
|
40
|
+
result += ' primary key';
|
|
41
|
+
}
|
|
96
42
|
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
let sql = 'create table if not exists ' + e.entityName + ' (' + result + '\r\n)';
|
|
46
|
+
if (SqlDatabase.LogToConsole)
|
|
47
|
+
console.log(sql);
|
|
48
|
+
await this.createCommand().execute(sql);
|
|
49
|
+
}
|
|
50
|
+
createCommand() {
|
|
101
51
|
return new WebSqlBridgeToSQLCommand(this.db);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
WebSqlDataProvider.prototype.addColumnSqlSyntax = function (x, dbName) {
|
|
111
|
-
var result = dbName;
|
|
52
|
+
}
|
|
53
|
+
async transaction(action) {
|
|
54
|
+
throw new Error("Method not implemented.");
|
|
55
|
+
}
|
|
56
|
+
addColumnSqlSyntax(x, dbName) {
|
|
57
|
+
let result = dbName;
|
|
112
58
|
if (x.valueType == Date)
|
|
113
59
|
result += " integer";
|
|
114
60
|
else if (x.valueType == Boolean)
|
|
@@ -122,60 +68,53 @@ var WebSqlDataProvider = /** @class */ (function () {
|
|
|
122
68
|
else
|
|
123
69
|
result += " text" + (x.allowNull ? " " : " default '' not null ");
|
|
124
70
|
return result;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
exports.WebSqlDataProvider = WebSqlDataProvider;
|
|
130
|
-
var WebSqlBridgeToSQLCommand = /** @class */ (function () {
|
|
71
|
+
}
|
|
72
|
+
toString() { return "WebSqlDataProvider"; }
|
|
73
|
+
}
|
|
74
|
+
class WebSqlBridgeToSQLCommand {
|
|
131
75
|
//@ts-ignore
|
|
132
|
-
|
|
76
|
+
constructor(source) {
|
|
133
77
|
this.source = source;
|
|
134
78
|
this.values = [];
|
|
135
79
|
}
|
|
136
|
-
|
|
80
|
+
addParameterAndReturnSqlToken(val) {
|
|
137
81
|
this.values.push(val);
|
|
138
82
|
return '~' + this.values.length + '~';
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
s = s.replace(mr, '?');
|
|
150
|
-
v.push(_this.values[Number.parseInt(mr.substring(1, mr.length - 1)) - 1]);
|
|
151
|
-
});
|
|
152
|
-
t.executeSql(s, v, function (t1, r) { return resolve(new WebSqlBridgeToSQLQueryResult(r)); }, function (t2, err) {
|
|
153
|
-
reject(err.message);
|
|
154
|
-
return undefined;
|
|
83
|
+
}
|
|
84
|
+
execute(sql) {
|
|
85
|
+
return new Promise((resolve, reject) => this.source.transaction(t => {
|
|
86
|
+
let s = sql;
|
|
87
|
+
let v = [];
|
|
88
|
+
var m = s.match(/~\d+~/g);
|
|
89
|
+
if (m != null)
|
|
90
|
+
m.forEach(mr => {
|
|
91
|
+
s = s.replace(mr, '?');
|
|
92
|
+
v.push(this.values[Number.parseInt(mr.substring(1, mr.length - 1)) - 1]);
|
|
155
93
|
});
|
|
94
|
+
t.executeSql(s, v, (t1, r) => resolve(new WebSqlBridgeToSQLQueryResult(r)), (t2, err) => {
|
|
95
|
+
reject(err.message);
|
|
96
|
+
return undefined;
|
|
156
97
|
});
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
var WebSqlBridgeToSQLQueryResult = /** @class */ (function () {
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
class WebSqlBridgeToSQLQueryResult {
|
|
162
102
|
//@ts-ignore
|
|
163
|
-
|
|
103
|
+
constructor(r) {
|
|
164
104
|
this.r = r;
|
|
165
105
|
this.rows = [];
|
|
166
|
-
for (
|
|
106
|
+
for (let i = 0; i < r.rows.length; i++) {
|
|
167
107
|
this.rows.push(r.rows.item(i));
|
|
168
108
|
}
|
|
169
109
|
}
|
|
170
|
-
|
|
110
|
+
getColumnKeyInResultForIndexInSelect(index) {
|
|
171
111
|
if (this.rows.length == 0)
|
|
172
112
|
return undefined;
|
|
173
|
-
|
|
174
|
-
for (
|
|
113
|
+
let i = 0;
|
|
114
|
+
for (let m in this.rows[0]) {
|
|
175
115
|
if (i++ == index)
|
|
176
116
|
return m;
|
|
177
117
|
}
|
|
178
118
|
return undefined;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
}());
|
|
119
|
+
}
|
|
120
|
+
}
|
package/src/entity.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,179 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.dbNameProviderImpl = exports.getDbNameProvider = exports.CustomSqlFilterBuilder = exports.FilterConsumerBridgeToSqlRequest = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var FilterConsumerBridgeToSqlRequest = /** @class */ (function () {
|
|
6
|
-
function FilterConsumerBridgeToSqlRequest(r, nameProvider) {
|
|
1
|
+
export class FilterConsumerBridgeToSqlRequest {
|
|
2
|
+
constructor(r, nameProvider) {
|
|
7
3
|
this.r = r;
|
|
8
4
|
this.nameProvider = nameProvider;
|
|
9
5
|
this.where = "";
|
|
10
6
|
this._addWhere = true;
|
|
11
7
|
this.promises = [];
|
|
12
8
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
case 1:
|
|
25
|
-
_b.trys.push([1, 6, 7, 8]);
|
|
26
|
-
p_1 = (e_1 = void 0, tslib_1.__values(p)), p_1_1 = p_1.next();
|
|
27
|
-
_b.label = 2;
|
|
28
|
-
case 2:
|
|
29
|
-
if (!!p_1_1.done) return [3 /*break*/, 5];
|
|
30
|
-
pr = p_1_1.value;
|
|
31
|
-
return [4 /*yield*/, pr];
|
|
32
|
-
case 3:
|
|
33
|
-
_b.sent();
|
|
34
|
-
_b.label = 4;
|
|
35
|
-
case 4:
|
|
36
|
-
p_1_1 = p_1.next();
|
|
37
|
-
return [3 /*break*/, 2];
|
|
38
|
-
case 5: return [3 /*break*/, 8];
|
|
39
|
-
case 6:
|
|
40
|
-
e_1_1 = _b.sent();
|
|
41
|
-
e_1 = { error: e_1_1 };
|
|
42
|
-
return [3 /*break*/, 8];
|
|
43
|
-
case 7:
|
|
44
|
-
try {
|
|
45
|
-
if (p_1_1 && !p_1_1.done && (_a = p_1.return)) _a.call(p_1);
|
|
46
|
-
}
|
|
47
|
-
finally { if (e_1) throw e_1.error; }
|
|
48
|
-
return [7 /*endfinally*/];
|
|
49
|
-
case 8: return [3 /*break*/, 0];
|
|
50
|
-
case 9: return [2 /*return*/, this.where];
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
FilterConsumerBridgeToSqlRequest.prototype.custom = function (key, customItem) {
|
|
9
|
+
async resolveWhere() {
|
|
10
|
+
while (this.promises.length > 0) {
|
|
11
|
+
let p = this.promises;
|
|
12
|
+
this.promises = [];
|
|
13
|
+
for (const pr of p) {
|
|
14
|
+
await pr;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return this.where;
|
|
18
|
+
}
|
|
19
|
+
custom(key, customItem) {
|
|
56
20
|
throw new Error("Custom filter should be translated before it gets here");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
case 2:
|
|
78
|
-
where = _b.sent();
|
|
79
|
-
if (!where)
|
|
80
|
-
return [2 /*return*/]; //since if any member of or is empty, then the entire or is irrelevant
|
|
81
|
-
if (where.length > 0) {
|
|
82
|
-
if (statement.length > 0) {
|
|
83
|
-
statement += " or ";
|
|
84
|
-
}
|
|
85
|
-
if (orElements.length > 1) {
|
|
86
|
-
statement += "(" + where + ")";
|
|
87
|
-
}
|
|
88
|
-
else
|
|
89
|
-
statement += where;
|
|
90
|
-
}
|
|
91
|
-
_b.label = 3;
|
|
92
|
-
case 3:
|
|
93
|
-
orElements_1_1 = orElements_1.next();
|
|
94
|
-
return [3 /*break*/, 1];
|
|
95
|
-
case 4: return [3 /*break*/, 7];
|
|
96
|
-
case 5:
|
|
97
|
-
e_2_1 = _b.sent();
|
|
98
|
-
e_2 = { error: e_2_1 };
|
|
99
|
-
return [3 /*break*/, 7];
|
|
100
|
-
case 6:
|
|
101
|
-
try {
|
|
102
|
-
if (orElements_1_1 && !orElements_1_1.done && (_a = orElements_1.return)) _a.call(orElements_1);
|
|
103
|
-
}
|
|
104
|
-
finally { if (e_2) throw e_2.error; }
|
|
105
|
-
return [7 /*endfinally*/];
|
|
106
|
-
case 7:
|
|
107
|
-
this.addToWhere("(" + statement + ")");
|
|
108
|
-
return [2 /*return*/];
|
|
21
|
+
}
|
|
22
|
+
or(orElements) {
|
|
23
|
+
let statement = '';
|
|
24
|
+
this.promises.push((async () => {
|
|
25
|
+
for (const element of orElements) {
|
|
26
|
+
let f = new FilterConsumerBridgeToSqlRequest(this.r, this.nameProvider);
|
|
27
|
+
f._addWhere = false;
|
|
28
|
+
element.__applyToConsumer(f);
|
|
29
|
+
let where = await f.resolveWhere();
|
|
30
|
+
if (!where)
|
|
31
|
+
return; //since if any member of or is empty, then the entire or is irrelevant
|
|
32
|
+
if (where.length > 0) {
|
|
33
|
+
if (statement.length > 0) {
|
|
34
|
+
statement += " or ";
|
|
35
|
+
}
|
|
36
|
+
if (orElements.length > 1) {
|
|
37
|
+
statement += "(" + where + ")";
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
statement += where;
|
|
109
41
|
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this.promises.push((
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.promises.push((
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return tslib_1.__generator(this, function (_a) {
|
|
130
|
-
if (val && val.length > 0)
|
|
131
|
-
this.addToWhere(this.nameProvider.nameOf(col) + " in (" + val.map(function (x) { return _this.r.addParameterAndReturnSqlToken(col.valueConverter.toDb(x)); }).join(",") + ")");
|
|
132
|
-
else
|
|
133
|
-
this.addToWhere('1 = 0 /*isIn with no values*/');
|
|
134
|
-
return [2 /*return*/];
|
|
135
|
-
});
|
|
136
|
-
}); })());
|
|
137
|
-
};
|
|
138
|
-
FilterConsumerBridgeToSqlRequest.prototype.isEqualTo = function (col, val) {
|
|
42
|
+
}
|
|
43
|
+
this.addToWhere("(" + statement + ")");
|
|
44
|
+
})());
|
|
45
|
+
}
|
|
46
|
+
isNull(col) {
|
|
47
|
+
this.promises.push((async () => this.addToWhere(this.nameProvider.nameOf(col) + ' is null'))());
|
|
48
|
+
}
|
|
49
|
+
isNotNull(col) {
|
|
50
|
+
this.promises.push((async () => this.addToWhere(this.nameProvider.nameOf(col) + ' is not null'))());
|
|
51
|
+
}
|
|
52
|
+
isIn(col, val) {
|
|
53
|
+
this.promises.push((async () => {
|
|
54
|
+
if (val && val.length > 0)
|
|
55
|
+
this.addToWhere(this.nameProvider.nameOf(col) + " in (" + val.map(x => this.r.addParameterAndReturnSqlToken(col.valueConverter.toDb(x))).join(",") + ")");
|
|
56
|
+
else
|
|
57
|
+
this.addToWhere('1 = 0 /*isIn with no values*/');
|
|
58
|
+
})());
|
|
59
|
+
}
|
|
60
|
+
isEqualTo(col, val) {
|
|
139
61
|
this.add(col, val, "=");
|
|
140
|
-
}
|
|
141
|
-
|
|
62
|
+
}
|
|
63
|
+
isDifferentFrom(col, val) {
|
|
142
64
|
this.add(col, val, "<>");
|
|
143
|
-
}
|
|
144
|
-
|
|
65
|
+
}
|
|
66
|
+
isGreaterOrEqualTo(col, val) {
|
|
145
67
|
this.add(col, val, ">=");
|
|
146
|
-
}
|
|
147
|
-
|
|
68
|
+
}
|
|
69
|
+
isGreaterThan(col, val) {
|
|
148
70
|
this.add(col, val, ">");
|
|
149
|
-
}
|
|
150
|
-
|
|
71
|
+
}
|
|
72
|
+
isLessOrEqualTo(col, val) {
|
|
151
73
|
this.add(col, val, "<=");
|
|
152
|
-
}
|
|
153
|
-
|
|
74
|
+
}
|
|
75
|
+
isLessThan(col, val) {
|
|
154
76
|
this.add(col, val, "<");
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
var x;
|
|
169
|
-
return tslib_1.__generator(this, function (_a) {
|
|
170
|
-
x = this.nameProvider.nameOf(col) + ' ' + operator + ' ' + this.r.addParameterAndReturnSqlToken(col.valueConverter.toDb(val));
|
|
171
|
-
this.addToWhere(x);
|
|
172
|
-
return [2 /*return*/];
|
|
173
|
-
});
|
|
174
|
-
}); })());
|
|
175
|
-
};
|
|
176
|
-
FilterConsumerBridgeToSqlRequest.prototype.addToWhere = function (x) {
|
|
77
|
+
}
|
|
78
|
+
containsCaseInsensitive(col, val) {
|
|
79
|
+
this.promises.push((async () => {
|
|
80
|
+
this.addToWhere('lower (' + this.nameProvider.nameOf(col) + ") like lower ('%" + val.replace(/'/g, '\'\'') + "%')");
|
|
81
|
+
})());
|
|
82
|
+
}
|
|
83
|
+
add(col, val, operator) {
|
|
84
|
+
this.promises.push((async () => {
|
|
85
|
+
let x = this.nameProvider.nameOf(col) + ' ' + operator + ' ' + this.r.addParameterAndReturnSqlToken(col.valueConverter.toDb(val));
|
|
86
|
+
this.addToWhere(x);
|
|
87
|
+
})());
|
|
88
|
+
}
|
|
89
|
+
addToWhere(x) {
|
|
177
90
|
if (this.where.length == 0) {
|
|
178
91
|
if (this._addWhere)
|
|
179
92
|
this.where += ' where ';
|
|
@@ -181,101 +94,46 @@ var FilterConsumerBridgeToSqlRequest = /** @class */ (function () {
|
|
|
181
94
|
else
|
|
182
95
|
this.where += ' and ';
|
|
183
96
|
this.where += x;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (!(databaseCustom === null || databaseCustom === void 0 ? void 0 : databaseCustom.buildSql)) return [3 /*break*/, 2];
|
|
193
|
-
item = new CustomSqlFilterBuilder(this.r);
|
|
194
|
-
return [4 /*yield*/, databaseCustom.buildSql(item)];
|
|
195
|
-
case 1:
|
|
196
|
-
_a.sent();
|
|
197
|
-
if (item.sql) {
|
|
198
|
-
this.addToWhere("(" + item.sql + ")");
|
|
199
|
-
}
|
|
200
|
-
_a.label = 2;
|
|
201
|
-
case 2: return [2 /*return*/];
|
|
97
|
+
}
|
|
98
|
+
databaseCustom(databaseCustom) {
|
|
99
|
+
this.promises.push((async () => {
|
|
100
|
+
if (databaseCustom?.buildSql) {
|
|
101
|
+
let item = new CustomSqlFilterBuilder(this.r);
|
|
102
|
+
await databaseCustom.buildSql(item);
|
|
103
|
+
if (item.sql) {
|
|
104
|
+
this.addToWhere("(" + item.sql + ")");
|
|
202
105
|
}
|
|
203
|
-
}
|
|
204
|
-
})
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
var CustomSqlFilterBuilder = /** @class */ (function () {
|
|
210
|
-
function CustomSqlFilterBuilder(r) {
|
|
106
|
+
}
|
|
107
|
+
})());
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export class CustomSqlFilterBuilder {
|
|
111
|
+
constructor(r) {
|
|
211
112
|
this.r = r;
|
|
212
113
|
this.sql = '';
|
|
213
114
|
}
|
|
214
|
-
|
|
115
|
+
addParameterAndReturnSqlToken(val, field) {
|
|
215
116
|
if (field)
|
|
216
117
|
val = field.valueConverter.toDb(val);
|
|
217
118
|
return this.r.addParameterAndReturnSqlToken(val);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
switch (_h.label) {
|
|
228
|
-
case 0:
|
|
229
|
-
result = new dbNameProviderImpl();
|
|
230
|
-
_h.label = 1;
|
|
231
|
-
case 1:
|
|
232
|
-
_h.trys.push([1, 6, 7, 8]);
|
|
233
|
-
_a = tslib_1.__values(meta.fields), _b = _a.next();
|
|
234
|
-
_h.label = 2;
|
|
235
|
-
case 2:
|
|
236
|
-
if (!!_b.done) return [3 /*break*/, 5];
|
|
237
|
-
f = _b.value;
|
|
238
|
-
_d = (_c = result.map).set;
|
|
239
|
-
_e = [f.key];
|
|
240
|
-
return [4 /*yield*/, f.getDbName()];
|
|
241
|
-
case 3:
|
|
242
|
-
_d.apply(_c, _e.concat([_h.sent()]));
|
|
243
|
-
_h.label = 4;
|
|
244
|
-
case 4:
|
|
245
|
-
_b = _a.next();
|
|
246
|
-
return [3 /*break*/, 2];
|
|
247
|
-
case 5: return [3 /*break*/, 8];
|
|
248
|
-
case 6:
|
|
249
|
-
e_3_1 = _h.sent();
|
|
250
|
-
e_3 = { error: e_3_1 };
|
|
251
|
-
return [3 /*break*/, 8];
|
|
252
|
-
case 7:
|
|
253
|
-
try {
|
|
254
|
-
if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
|
|
255
|
-
}
|
|
256
|
-
finally { if (e_3) throw e_3.error; }
|
|
257
|
-
return [7 /*endfinally*/];
|
|
258
|
-
case 8:
|
|
259
|
-
_f = result;
|
|
260
|
-
return [4 /*yield*/, meta.getDbName()];
|
|
261
|
-
case 9:
|
|
262
|
-
_f.entityName = _h.sent();
|
|
263
|
-
return [2 /*return*/, result];
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export async function getDbNameProvider(meta) {
|
|
122
|
+
var result = new dbNameProviderImpl();
|
|
123
|
+
for (const f of meta.fields) {
|
|
124
|
+
result.map.set(f.key, await f.getDbName());
|
|
125
|
+
}
|
|
126
|
+
result.entityName = await meta.getDbName();
|
|
127
|
+
return result;
|
|
267
128
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
function dbNameProviderImpl() {
|
|
129
|
+
export class dbNameProviderImpl {
|
|
130
|
+
constructor() {
|
|
271
131
|
this.map = new Map();
|
|
272
132
|
}
|
|
273
|
-
|
|
133
|
+
nameOf(field) {
|
|
274
134
|
return this.map.get(field.key);
|
|
275
|
-
}
|
|
276
|
-
|
|
135
|
+
}
|
|
136
|
+
isDbReadonly(x) {
|
|
277
137
|
return (x.dbReadOnly || x.isServerExpression || this.nameOf(x) != x.options.dbName);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
}());
|
|
281
|
-
exports.dbNameProviderImpl = dbNameProviderImpl;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|