remult 0.12.4 → 0.12.8
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/package.json
CHANGED
package/remult-knex/index.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { DataProvider, EntityDataProvider, EntityMetadata, FieldMetadata, Filter, Remult } from "..";
|
|
1
|
+
import { DataProvider, EntityDataProvider, EntityFilter, EntityMetadata, FieldMetadata, Filter, Remult } from "..";
|
|
2
2
|
import { Knex } from 'knex';
|
|
3
3
|
import { FilterConsumer } from "../src/filter/filter-interfaces";
|
|
4
|
-
import {
|
|
4
|
+
import { dbNameProvider } from "../src/filter/filter-consumer-bridge-to-sql-request";
|
|
5
5
|
export declare class KnexDataProvider implements DataProvider {
|
|
6
6
|
knex: Knex;
|
|
7
7
|
constructor(knex: Knex);
|
|
8
8
|
getEntityDataProvider(entity: EntityMetadata<any>): EntityDataProvider;
|
|
9
9
|
transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
|
|
10
|
+
static customFilter(build: CustomKnexFilterBuilderFunction): EntityFilter<any>;
|
|
10
11
|
supportsCustomFilter?: boolean;
|
|
11
12
|
}
|
|
13
|
+
export declare type CustomKnexFilterBuilderFunction = () => Promise<(builder: Knex.QueryBuilder) => void>;
|
|
12
14
|
export declare class FilterConsumerBridgeToKnexRequest implements FilterConsumer {
|
|
13
15
|
private nameProvider;
|
|
14
16
|
_addWhere: boolean;
|
|
@@ -29,7 +31,9 @@ export declare class FilterConsumerBridgeToKnexRequest implements FilterConsumer
|
|
|
29
31
|
isLessThan(col: FieldMetadata, val: any): void;
|
|
30
32
|
containsCaseInsensitive(col: FieldMetadata, val: any): void;
|
|
31
33
|
private add;
|
|
32
|
-
databaseCustom(databaseCustom:
|
|
34
|
+
databaseCustom(databaseCustom: {
|
|
35
|
+
buildKnex: CustomKnexFilterBuilderFunction;
|
|
36
|
+
}): void;
|
|
33
37
|
}
|
|
34
38
|
export declare class KnexSchemaBuilder {
|
|
35
39
|
private knex;
|
package/remult-knex/index.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.createKnexDataProvider = exports.buildColumn = exports.KnexSchemaBuilder
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var __1 = require("..");
|
|
6
6
|
var knex_1 = require("knex");
|
|
7
|
+
var filter_interfaces_1 = require("../src/filter/filter-interfaces");
|
|
7
8
|
var filter_consumer_bridge_to_sql_request_1 = require("../src/filter/filter-consumer-bridge-to-sql-request");
|
|
8
9
|
var context_1 = require("../src/context");
|
|
9
10
|
var valueConverters_1 = require("../valueConverters");
|
|
@@ -43,6 +44,14 @@ var KnexDataProvider = /** @class */ (function () {
|
|
|
43
44
|
});
|
|
44
45
|
});
|
|
45
46
|
};
|
|
47
|
+
KnexDataProvider.customFilter = function (build) {
|
|
48
|
+
var _a;
|
|
49
|
+
return _a = {},
|
|
50
|
+
_a[filter_interfaces_1.customDatabaseFilterToken] = {
|
|
51
|
+
buildKnex: build
|
|
52
|
+
},
|
|
53
|
+
_a;
|
|
54
|
+
};
|
|
46
55
|
return KnexDataProvider;
|
|
47
56
|
}());
|
|
48
57
|
exports.KnexDataProvider = KnexDataProvider;
|
|
@@ -364,7 +373,6 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
364
373
|
};
|
|
365
374
|
FilterConsumerBridgeToKnexRequest.prototype.or = function (orElements) {
|
|
366
375
|
var _this = this;
|
|
367
|
-
var statement = '';
|
|
368
376
|
this.promises.push((function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
369
377
|
var result, _loop_1, this_1, orElements_1, orElements_1_1, element, e_5_1;
|
|
370
378
|
var e_5, _a;
|
|
@@ -476,16 +484,22 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
476
484
|
this.result.push(function (b) { return b.where(_this.nameProvider.nameOf(col), operator, col.valueConverter.toDb(val)); });
|
|
477
485
|
};
|
|
478
486
|
FilterConsumerBridgeToKnexRequest.prototype.databaseCustom = function (databaseCustom) {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
487
|
+
var _this = this;
|
|
488
|
+
this.promises.push((function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
489
|
+
var _a, _b;
|
|
490
|
+
return tslib_1.__generator(this, function (_c) {
|
|
491
|
+
switch (_c.label) {
|
|
492
|
+
case 0:
|
|
493
|
+
if (!(databaseCustom === null || databaseCustom === void 0 ? void 0 : databaseCustom.buildKnex)) return [3 /*break*/, 2];
|
|
494
|
+
_b = (_a = this.result).push;
|
|
495
|
+
return [4 /*yield*/, databaseCustom.buildKnex()];
|
|
496
|
+
case 1:
|
|
497
|
+
_b.apply(_a, [_c.sent()]);
|
|
498
|
+
_c.label = 2;
|
|
499
|
+
case 2: return [2 /*return*/];
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
}); })());
|
|
489
503
|
};
|
|
490
504
|
return FilterConsumerBridgeToKnexRequest;
|
|
491
505
|
}());
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
|
+
var __1 = require("../..");
|
|
4
5
|
var context_1 = require("../context");
|
|
5
6
|
var remult_knex_1 = require("../../remult-knex");
|
|
6
7
|
var Knex = require("knex");
|
|
7
8
|
var dotenv_1 = require("dotenv");
|
|
9
|
+
var backend_database_test_setup_backend_spec_1 = require("./backend-database-test-setup.backend-spec");
|
|
10
|
+
var entityWithValidations_1 = require("../shared-tests/entityWithValidations");
|
|
8
11
|
dotenv_1.config();
|
|
9
12
|
describe("test", function () {
|
|
10
13
|
var remult;
|
|
@@ -21,3 +24,112 @@ describe("test", function () {
|
|
|
21
24
|
});
|
|
22
25
|
}); });
|
|
23
26
|
});
|
|
27
|
+
backend_database_test_setup_backend_spec_1.testPostgresImplementation("sql filter", function (_a) {
|
|
28
|
+
var createEntity = _a.createEntity;
|
|
29
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
30
|
+
var s, _b;
|
|
31
|
+
return tslib_1.__generator(this, function (_c) {
|
|
32
|
+
switch (_c.label) {
|
|
33
|
+
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
34
|
+
case 1:
|
|
35
|
+
s = _c.sent();
|
|
36
|
+
_b = expect;
|
|
37
|
+
return [4 /*yield*/, s.find({
|
|
38
|
+
where: __1.SqlDatabase.customFilter(function (build) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
39
|
+
return tslib_1.__generator(this, function (_a) {
|
|
40
|
+
build.sql = s.metadata.fields.myId.options.dbName + ' in (1,3)';
|
|
41
|
+
return [2 /*return*/];
|
|
42
|
+
});
|
|
43
|
+
}); })
|
|
44
|
+
})];
|
|
45
|
+
case 2:
|
|
46
|
+
_b.apply(void 0, [(_c.sent()).length]).toBe(2);
|
|
47
|
+
return [2 /*return*/];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}, false);
|
|
52
|
+
backend_database_test_setup_backend_spec_1.testPostgresImplementation("sql filter2", function (_a) {
|
|
53
|
+
var createEntity = _a.createEntity;
|
|
54
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
55
|
+
var s, _b;
|
|
56
|
+
return tslib_1.__generator(this, function (_c) {
|
|
57
|
+
switch (_c.label) {
|
|
58
|
+
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
59
|
+
case 1:
|
|
60
|
+
s = _c.sent();
|
|
61
|
+
_b = expect;
|
|
62
|
+
return [4 /*yield*/, s.find({
|
|
63
|
+
where: {
|
|
64
|
+
$or: [
|
|
65
|
+
__1.SqlDatabase.customFilter(function (build) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
66
|
+
return tslib_1.__generator(this, function (_a) {
|
|
67
|
+
build.sql = s.metadata.fields.myId.options.dbName + ' in (1,3)';
|
|
68
|
+
return [2 /*return*/];
|
|
69
|
+
});
|
|
70
|
+
}); }),
|
|
71
|
+
{
|
|
72
|
+
myId: 2
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
})];
|
|
77
|
+
case 2:
|
|
78
|
+
_b.apply(void 0, [(_c.sent()).length]).toBe(3);
|
|
79
|
+
return [2 /*return*/];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}, false);
|
|
84
|
+
backend_database_test_setup_backend_spec_1.testKnexPGSqlImpl("knex filter", function (_a) {
|
|
85
|
+
var createEntity = _a.createEntity;
|
|
86
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
87
|
+
var s, _b;
|
|
88
|
+
return tslib_1.__generator(this, function (_c) {
|
|
89
|
+
switch (_c.label) {
|
|
90
|
+
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
91
|
+
case 1:
|
|
92
|
+
s = _c.sent();
|
|
93
|
+
_b = expect;
|
|
94
|
+
return [4 /*yield*/, s.find({
|
|
95
|
+
where: remult_knex_1.KnexDataProvider.customFilter(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
96
|
+
return tslib_1.__generator(this, function (_a) {
|
|
97
|
+
return [2 /*return*/, function (build) { return build.whereIn(s.metadata.fields.myId.options.dbName, [1, 3]); }];
|
|
98
|
+
});
|
|
99
|
+
}); })
|
|
100
|
+
})];
|
|
101
|
+
case 2:
|
|
102
|
+
_b.apply(void 0, [(_c.sent()).length]).toBe(2);
|
|
103
|
+
return [2 /*return*/];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}, false);
|
|
108
|
+
backend_database_test_setup_backend_spec_1.testKnexPGSqlImpl("knex filter2", function (_a) {
|
|
109
|
+
var createEntity = _a.createEntity;
|
|
110
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
111
|
+
var s, _b;
|
|
112
|
+
return tslib_1.__generator(this, function (_c) {
|
|
113
|
+
switch (_c.label) {
|
|
114
|
+
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
115
|
+
case 1:
|
|
116
|
+
s = _c.sent();
|
|
117
|
+
_b = expect;
|
|
118
|
+
return [4 /*yield*/, s.find({
|
|
119
|
+
where: {
|
|
120
|
+
$or: [remult_knex_1.KnexDataProvider.customFilter(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
121
|
+
return tslib_1.__generator(this, function (_a) {
|
|
122
|
+
return [2 /*return*/, function (build) { return build.whereIn(s.metadata.fields.myId.options.dbName, [1, 3]); }];
|
|
123
|
+
});
|
|
124
|
+
}); }), {
|
|
125
|
+
myId: 4
|
|
126
|
+
}]
|
|
127
|
+
}
|
|
128
|
+
})];
|
|
129
|
+
case 2:
|
|
130
|
+
_b.apply(void 0, [(_c.sent()).length]).toBe(3);
|
|
131
|
+
return [2 /*return*/];
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}, false);
|