@steedos/objectql 3.0.13-beta.3 → 3.0.13-beta.30
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/lib/actions/field_updates.js +84 -153
- package/lib/actions/field_updates.js.map +1 -1
- package/lib/actions/index.js +1 -1
- package/lib/actions/workflow_notifications.js +50 -111
- package/lib/actions/workflow_notifications.js.map +1 -1
- package/lib/actions/workflow_outbound_messages.js +43 -94
- package/lib/actions/workflow_outbound_messages.js.map +1 -1
- package/lib/actions/workflow_rule.js +80 -177
- package/lib/actions/workflow_rule.js.map +1 -1
- package/lib/broker.js +19 -49
- package/lib/broker.js.map +1 -1
- package/lib/driver/field-encrytion/index.js +1 -1
- package/lib/driver/field-encrytion/mongosharedconst.js +17 -17
- package/lib/driver/field-encrytion/mongosharedconst.js.map +1 -1
- package/lib/driver/format.js +3 -3
- package/lib/driver/format.js.map +1 -1
- package/lib/driver/index.js +1 -1
- package/lib/driver/metadata.js +283 -387
- package/lib/driver/metadata.js.map +1 -1
- package/lib/driver/metadataOld.js +104 -105
- package/lib/driver/metadataOld.js.map +1 -1
- package/lib/driver/meteorMongo.js +5 -8
- package/lib/driver/meteorMongo.js.map +1 -1
- package/lib/driver/mongo.js +321 -506
- package/lib/driver/mongo.js.map +1 -1
- package/lib/driver/mysql.js +16 -20
- package/lib/driver/mysql.js.map +1 -1
- package/lib/driver/oracle.js +25 -38
- package/lib/driver/oracle.js.map +1 -1
- package/lib/driver/postgres.js +16 -20
- package/lib/driver/postgres.js.map +1 -1
- package/lib/driver/sqlite3.js +15 -19
- package/lib/driver/sqlite3.js.map +1 -1
- package/lib/driver/sqlserver.js +20 -33
- package/lib/driver/sqlserver.js.map +1 -1
- package/lib/errors/index.js +10 -11
- package/lib/errors/index.js.map +1 -1
- package/lib/formula/core.js +307 -594
- package/lib/formula/core.js.map +1 -1
- package/lib/formula/field_formula.js +80 -126
- package/lib/formula/field_formula.js.map +1 -1
- package/lib/formula/index.js +56 -97
- package/lib/formula/index.js.map +1 -1
- package/lib/formula/params.js +11 -11
- package/lib/formula/params.js.map +1 -1
- package/lib/formula/recompute.js +41 -166
- package/lib/formula/recompute.js.map +1 -1
- package/lib/formula/simple_params.js +12 -12
- package/lib/formula/simple_params.js.map +1 -1
- package/lib/formula/util.js +43 -67
- package/lib/formula/util.js.map +1 -1
- package/lib/functions/function.js +62 -87
- package/lib/functions/function.js.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/services/datasourceServiceFactory.js +77 -111
- package/lib/services/datasourceServiceFactory.js.map +1 -1
- package/lib/services/index.js +3 -3
- package/lib/services/index.js.map +1 -1
- package/lib/summary/core.js +162 -355
- package/lib/summary/core.js.map +1 -1
- package/lib/summary/field_summary.js +44 -71
- package/lib/summary/field_summary.js.map +1 -1
- package/lib/summary/index.js +65 -80
- package/lib/summary/index.js.map +1 -1
- package/lib/summary/recompute.js +19 -47
- package/lib/summary/recompute.js.map +1 -1
- package/lib/triggers/trigger.js +101 -142
- package/lib/triggers/trigger.js.map +1 -1
- package/lib/ts-types/index.js +1 -1
- package/lib/typeorm/driver.js +250 -450
- package/lib/typeorm/driver.js.map +1 -1
- package/lib/typeorm/index.js +1 -1
- package/lib/typeorm/util.js +28 -28
- package/lib/typeorm/util.js.map +1 -1
- package/lib/types/action.js +24 -33
- package/lib/types/action.js.map +1 -1
- package/lib/types/app.js +210 -355
- package/lib/types/app.js.map +1 -1
- package/lib/types/connection.js +42 -78
- package/lib/types/connection.js.map +1 -1
- package/lib/types/dashboard.js +56 -77
- package/lib/types/dashboard.js.map +1 -1
- package/lib/types/datasource.js +359 -705
- package/lib/types/datasource.js.map +1 -1
- package/lib/types/defaultValue.js +53 -65
- package/lib/types/defaultValue.js.map +1 -1
- package/lib/types/field.js +165 -137
- package/lib/types/field.js.map +1 -1
- package/lib/types/field_permission.js +35 -66
- package/lib/types/field_permission.js.map +1 -1
- package/lib/types/index.js +1 -1
- package/lib/types/list_view.js +36 -43
- package/lib/types/list_view.js.map +1 -1
- package/lib/types/metadata.js +6 -6
- package/lib/types/metadata.js.map +1 -1
- package/lib/types/method_base.js +95 -128
- package/lib/types/method_base.js.map +1 -1
- package/lib/types/object.js +2005 -3015
- package/lib/types/object.js.map +1 -1
- package/lib/types/object_events.js +24 -37
- package/lib/types/object_events.js.map +1 -1
- package/lib/types/object_layouts.js +15 -38
- package/lib/types/object_layouts.js.map +1 -1
- package/lib/types/object_permission.js +99 -85
- package/lib/types/object_permission.js.map +1 -1
- package/lib/types/report.js +70 -98
- package/lib/types/report.js.map +1 -1
- package/lib/types/restrictionRule.js +47 -96
- package/lib/types/restrictionRule.js.map +1 -1
- package/lib/types/schema.js +115 -177
- package/lib/types/schema.js.map +1 -1
- package/lib/types/shareRule.js +53 -102
- package/lib/types/shareRule.js.map +1 -1
- package/lib/types/trigger.js +43 -56
- package/lib/types/trigger.js.map +1 -1
- package/lib/types/validation_rules.js +18 -56
- package/lib/types/validation_rules.js.map +1 -1
- package/lib/util/convert.js +24 -24
- package/lib/util/convert.js.map +1 -1
- package/lib/util/field.js +16 -28
- package/lib/util/field.js.map +1 -1
- package/lib/util/function_expression.js +7 -8
- package/lib/util/function_expression.js.map +1 -1
- package/lib/util/index.js +79 -97
- package/lib/util/index.js.map +1 -1
- package/lib/util/locale.js +4 -4
- package/lib/util/locale.js.map +1 -1
- package/lib/util/permission_shares.js +7 -7
- package/lib/util/permission_shares.js.map +1 -1
- package/lib/util/suffix.js +19 -19
- package/lib/util/suffix.js.map +1 -1
- package/lib/util/transform.js +1 -1
- package/lib/validators/index.js +10 -10
- package/lib/validators/index.js.map +1 -1
- package/package.json +12 -12
package/lib/driver/mongo.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SteedosMongoDriver = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var SLOW_QUERY_THRESHOLD_MS = 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
const mongodb_1 = require("mongodb");
|
|
6
|
+
const filters_1 = require("@steedos/filters");
|
|
7
|
+
const odata_v4_mongodb_1 = require("@steedos/odata-v4-mongodb");
|
|
8
|
+
const _ = require("underscore");
|
|
9
|
+
const field_encrytion_1 = require("./field-encrytion");
|
|
10
|
+
const format_1 = require("./format");
|
|
11
|
+
let monitor_enabled = false;
|
|
12
|
+
let SLOW_QUERY_THRESHOLD_MS = 0;
|
|
14
13
|
if (process.env.STEEDOS_MONGODB_SLOW_QUERY_THRESHOLD) {
|
|
15
14
|
monitor_enabled = true;
|
|
16
15
|
SLOW_QUERY_THRESHOLD_MS = Number(process.env.STEEDOS_MONGODB_SLOW_QUERY_THRESHOLD);
|
|
17
16
|
}
|
|
18
|
-
|
|
17
|
+
const runningCommands = new Map();
|
|
19
18
|
function connectAndMonitor(client) {
|
|
20
|
-
client.on("commandStarted",
|
|
19
|
+
client.on("commandStarted", (event) => {
|
|
21
20
|
runningCommands.set(event.requestId, {
|
|
22
21
|
startTime: Date.now(),
|
|
23
22
|
commandName: event.commandName,
|
|
@@ -25,53 +24,58 @@ function connectAndMonitor(client) {
|
|
|
25
24
|
command: event.command,
|
|
26
25
|
});
|
|
27
26
|
});
|
|
28
|
-
client.on("commandSucceeded",
|
|
29
|
-
|
|
27
|
+
client.on("commandSucceeded", (event) => {
|
|
28
|
+
const commandInfo = runningCommands.get(event.requestId);
|
|
30
29
|
if (!commandInfo)
|
|
31
30
|
return;
|
|
32
|
-
|
|
31
|
+
const duration = Date.now() - commandInfo.startTime;
|
|
33
32
|
runningCommands.delete(event.requestId);
|
|
34
33
|
if (duration >= SLOW_QUERY_THRESHOLD_MS) {
|
|
35
|
-
console.warn(
|
|
36
|
-
console.warn(
|
|
37
|
-
console.warn(
|
|
38
|
-
console.warn(
|
|
39
|
-
console.warn(
|
|
34
|
+
console.warn(`🚨 慢查询检测到 (成功):`);
|
|
35
|
+
console.warn(` 命令: ${commandInfo.commandName}`);
|
|
36
|
+
console.warn(` 耗时: ${duration} ms`);
|
|
37
|
+
console.warn(` 数据库: ${commandInfo.databaseName}`);
|
|
38
|
+
console.warn(` command: ${JSON.stringify(commandInfo.command)}`);
|
|
40
39
|
}
|
|
41
40
|
});
|
|
42
|
-
client.on("commandFailed",
|
|
43
|
-
|
|
41
|
+
client.on("commandFailed", (event) => {
|
|
42
|
+
const commandInfo = runningCommands.get(event.requestId);
|
|
44
43
|
if (!commandInfo)
|
|
45
44
|
return;
|
|
46
|
-
|
|
45
|
+
const duration = Date.now() - commandInfo.startTime;
|
|
47
46
|
runningCommands.delete(event.requestId);
|
|
48
47
|
if (duration >= SLOW_QUERY_THRESHOLD_MS) {
|
|
49
|
-
console.error(
|
|
50
|
-
console.error(
|
|
51
|
-
console.error(
|
|
52
|
-
console.error(
|
|
53
|
-
console.error(
|
|
48
|
+
console.error(`❌ 慢操作检测到 (失败):`);
|
|
49
|
+
console.error(` 命令: ${commandInfo.commandName}`);
|
|
50
|
+
console.error(` 耗时: ${duration} ms`);
|
|
51
|
+
console.error(` 错误: ${event.failure.message}`);
|
|
52
|
+
console.error(` command: ${JSON.stringify(commandInfo.command)}`);
|
|
54
53
|
}
|
|
55
54
|
});
|
|
56
55
|
}
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
class SteedosMongoDriver {
|
|
57
|
+
_url;
|
|
58
|
+
_client;
|
|
59
|
+
_config;
|
|
60
|
+
_collections;
|
|
61
|
+
_encryption;
|
|
62
|
+
constructor(config) {
|
|
59
63
|
this._collections = {};
|
|
60
64
|
this._config = config;
|
|
61
65
|
this._url = this.buildConnectionUrl();
|
|
62
66
|
}
|
|
63
|
-
|
|
67
|
+
buildConnectionUrl() {
|
|
64
68
|
if (this._config.url)
|
|
65
69
|
return this._config.url;
|
|
66
|
-
|
|
67
|
-
?
|
|
70
|
+
const credentialsUrlPart = this._config.username && this._config.password
|
|
71
|
+
? `${this._config.username}:${this._config.password}@`
|
|
68
72
|
: "";
|
|
69
73
|
if (!this._config.database) {
|
|
70
74
|
throw new Error("Not find database");
|
|
71
75
|
}
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
|
|
76
|
+
return `mongodb://${credentialsUrlPart}${this._config.host || "127.0.0.1"}:${this._config.port || "27017"}/${this._config.database}`;
|
|
77
|
+
}
|
|
78
|
+
getSupportedColumnTypes() {
|
|
75
79
|
return [
|
|
76
80
|
index_1.SteedosFieldDBType.varchar,
|
|
77
81
|
index_1.SteedosFieldDBType.text,
|
|
@@ -82,118 +86,74 @@ var SteedosMongoDriver = (function () {
|
|
|
82
86
|
index_1.SteedosFieldDBType.json,
|
|
83
87
|
index_1.SteedosFieldDBType.array,
|
|
84
88
|
];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
altKeyName = (0, field_encrytion_1.getMongoFieldEncryptionConsts)().altKeyName;
|
|
94
|
-
encryption = this._encryption;
|
|
95
|
-
return [4, encryption.encrypt(value, {
|
|
96
|
-
keyAltName: altKeyName,
|
|
97
|
-
algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic",
|
|
98
|
-
})];
|
|
99
|
-
case 1:
|
|
100
|
-
encryptValue = _a.sent();
|
|
101
|
-
return [2, encryptValue];
|
|
102
|
-
case 2: return [2, value];
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
SteedosMongoDriver.prototype.decryptValue = function (value) {
|
|
108
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
109
|
-
var encryption, decryptValue;
|
|
110
|
-
return tslib_1.__generator(this, function (_a) {
|
|
111
|
-
switch (_a.label) {
|
|
112
|
-
case 0:
|
|
113
|
-
if (!this._encryption) return [3, 2];
|
|
114
|
-
encryption = this._encryption;
|
|
115
|
-
return [4, encryption.decrypt(value)];
|
|
116
|
-
case 1:
|
|
117
|
-
decryptValue = _a.sent();
|
|
118
|
-
return [2, decryptValue];
|
|
119
|
-
case 2: return [2, value];
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
};
|
|
124
|
-
SteedosMongoDriver.prototype.connect = function () {
|
|
125
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
126
|
-
var ClientEncryption, _a, keyVaultNamespace, getKMSProviders, kmsProvider, _b, _c;
|
|
127
|
-
return tslib_1.__generator(this, function (_d) {
|
|
128
|
-
switch (_d.label) {
|
|
129
|
-
case 0:
|
|
130
|
-
if (!!this._client) return [3, 6];
|
|
131
|
-
if (!process.env.STEEDOS_CSFLE_MASTER_KEY) return [3, 3];
|
|
132
|
-
ClientEncryption = require("mongodb-client-encryption").ClientEncryption;
|
|
133
|
-
_a = (0, field_encrytion_1.getMongoFieldEncryptionConsts)(), keyVaultNamespace = _a.keyVaultNamespace, getKMSProviders = _a.getKMSProviders;
|
|
134
|
-
return [4, getKMSProviders()];
|
|
135
|
-
case 1:
|
|
136
|
-
kmsProvider = _d.sent();
|
|
137
|
-
_b = this;
|
|
138
|
-
return [4, mongodb_1.MongoClient.connect(this._url, {
|
|
139
|
-
useNewUrlParser: true,
|
|
140
|
-
useUnifiedTopology: true,
|
|
141
|
-
monitorCommands: true,
|
|
142
|
-
autoEncryption: {
|
|
143
|
-
keyVaultNamespace: keyVaultNamespace,
|
|
144
|
-
kmsProviders: kmsProvider,
|
|
145
|
-
bypassAutoEncryption: true,
|
|
146
|
-
},
|
|
147
|
-
})];
|
|
148
|
-
case 2:
|
|
149
|
-
_b._client = _d.sent();
|
|
150
|
-
this._encryption = new ClientEncryption(this._client, {
|
|
151
|
-
keyVaultNamespace: keyVaultNamespace,
|
|
152
|
-
kmsProviders: kmsProvider,
|
|
153
|
-
});
|
|
154
|
-
return [3, 5];
|
|
155
|
-
case 3:
|
|
156
|
-
_c = this;
|
|
157
|
-
return [4, mongodb_1.MongoClient.connect(this._url, {
|
|
158
|
-
useNewUrlParser: true,
|
|
159
|
-
useUnifiedTopology: true,
|
|
160
|
-
monitorCommands: monitor_enabled,
|
|
161
|
-
})];
|
|
162
|
-
case 4:
|
|
163
|
-
_c._client = _d.sent();
|
|
164
|
-
_d.label = 5;
|
|
165
|
-
case 5:
|
|
166
|
-
if (monitor_enabled) {
|
|
167
|
-
connectAndMonitor(this._client);
|
|
168
|
-
}
|
|
169
|
-
return [2, true];
|
|
170
|
-
case 6: return [2];
|
|
171
|
-
}
|
|
89
|
+
}
|
|
90
|
+
async encryptValue(value) {
|
|
91
|
+
if (this._encryption) {
|
|
92
|
+
const { altKeyName } = (0, field_encrytion_1.getMongoFieldEncryptionConsts)();
|
|
93
|
+
const encryption = this._encryption;
|
|
94
|
+
let encryptValue = await encryption.encrypt(value, {
|
|
95
|
+
keyAltName: altKeyName,
|
|
96
|
+
algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic",
|
|
172
97
|
});
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
98
|
+
return encryptValue;
|
|
99
|
+
}
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
async decryptValue(value) {
|
|
103
|
+
if (this._encryption) {
|
|
104
|
+
const encryption = this._encryption;
|
|
105
|
+
let decryptValue = await encryption.decrypt(value);
|
|
106
|
+
return decryptValue;
|
|
107
|
+
}
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
async connect() {
|
|
111
|
+
if (!this._client) {
|
|
112
|
+
if (process.env.STEEDOS_CSFLE_MASTER_KEY) {
|
|
113
|
+
const { ClientEncryption } = require("mongodb-client-encryption");
|
|
114
|
+
const { keyVaultNamespace, getKMSProviders } = (0, field_encrytion_1.getMongoFieldEncryptionConsts)();
|
|
115
|
+
const kmsProvider = await getKMSProviders();
|
|
116
|
+
this._client = await mongodb_1.MongoClient.connect(this._url, {
|
|
117
|
+
useNewUrlParser: true,
|
|
118
|
+
useUnifiedTopology: true,
|
|
119
|
+
monitorCommands: true,
|
|
120
|
+
autoEncryption: {
|
|
121
|
+
keyVaultNamespace: keyVaultNamespace,
|
|
122
|
+
kmsProviders: kmsProvider,
|
|
123
|
+
bypassAutoEncryption: true,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
this._encryption = new ClientEncryption(this._client, {
|
|
127
|
+
keyVaultNamespace: keyVaultNamespace,
|
|
128
|
+
kmsProviders: kmsProvider,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
this._client = await mongodb_1.MongoClient.connect(this._url, {
|
|
133
|
+
useNewUrlParser: true,
|
|
134
|
+
useUnifiedTopology: true,
|
|
135
|
+
monitorCommands: monitor_enabled,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (monitor_enabled) {
|
|
139
|
+
connectAndMonitor(this._client);
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
getClient() {
|
|
176
145
|
return this._client;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return [2, true];
|
|
189
|
-
case 2: return [2];
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
|
-
SteedosMongoDriver.prototype.formatFiltersToMongoQuery = function (filters) {
|
|
195
|
-
var emptyFilters = {};
|
|
196
|
-
var odataQuery = "";
|
|
146
|
+
}
|
|
147
|
+
async close() {
|
|
148
|
+
if (this._client) {
|
|
149
|
+
await this._client.close();
|
|
150
|
+
this._client = null;
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
formatFiltersToMongoQuery(filters) {
|
|
155
|
+
let emptyFilters = {};
|
|
156
|
+
let odataQuery = "";
|
|
197
157
|
if (_.isString(filters)) {
|
|
198
158
|
odataQuery = filters;
|
|
199
159
|
}
|
|
@@ -203,11 +163,11 @@ var SteedosMongoDriver = (function () {
|
|
|
203
163
|
if (!odataQuery) {
|
|
204
164
|
return emptyFilters;
|
|
205
165
|
}
|
|
206
|
-
|
|
166
|
+
let query = (0, odata_v4_mongodb_1.createFilter)(odataQuery);
|
|
207
167
|
return query;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
168
|
+
}
|
|
169
|
+
getMongoFilters(filters) {
|
|
170
|
+
let emptyFilters = {};
|
|
211
171
|
if (_.isUndefined(filters)) {
|
|
212
172
|
return emptyFilters;
|
|
213
173
|
}
|
|
@@ -217,63 +177,63 @@ var SteedosMongoDriver = (function () {
|
|
|
217
177
|
if (_.isArray(filters) && !filters.length) {
|
|
218
178
|
return emptyFilters;
|
|
219
179
|
}
|
|
220
|
-
|
|
180
|
+
let mongoFilters = this.formatFiltersToMongoQuery(filters);
|
|
221
181
|
return mongoFilters;
|
|
222
|
-
}
|
|
223
|
-
|
|
182
|
+
}
|
|
183
|
+
getMongoFieldsOptions(fields) {
|
|
224
184
|
if (typeof fields == "string") {
|
|
225
|
-
fields = fields.split(",").map(
|
|
185
|
+
fields = fields.split(",").map((n) => {
|
|
226
186
|
return n.trim();
|
|
227
187
|
});
|
|
228
188
|
}
|
|
229
189
|
if (!(fields && fields.length)) {
|
|
230
190
|
return {};
|
|
231
191
|
}
|
|
232
|
-
|
|
233
|
-
fields.forEach(
|
|
192
|
+
let projection = {};
|
|
193
|
+
fields.forEach((field) => {
|
|
234
194
|
if (field) {
|
|
235
195
|
projection[field] = 1;
|
|
236
196
|
}
|
|
237
197
|
});
|
|
238
198
|
return projection;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
199
|
+
}
|
|
200
|
+
getMongoSortOptions(sort) {
|
|
201
|
+
let result = undefined;
|
|
242
202
|
if (sort && typeof sort === "string") {
|
|
243
|
-
|
|
203
|
+
let arraySort = sort.split(",").map((n) => {
|
|
244
204
|
return n.trim();
|
|
245
205
|
});
|
|
246
|
-
|
|
247
|
-
arraySort.forEach(
|
|
206
|
+
let stringSort = "";
|
|
207
|
+
arraySort.forEach((n) => {
|
|
248
208
|
if (n) {
|
|
249
|
-
|
|
209
|
+
stringSort += `${n},`;
|
|
250
210
|
}
|
|
251
211
|
});
|
|
252
|
-
|
|
253
|
-
result = (0, odata_v4_mongodb_1.createQuery)(
|
|
212
|
+
stringSort = stringSort.replace(/,$/g, "");
|
|
213
|
+
result = (0, odata_v4_mongodb_1.createQuery)(`$orderby=${stringSort}`).sort;
|
|
254
214
|
}
|
|
255
215
|
return result;
|
|
256
|
-
}
|
|
257
|
-
|
|
216
|
+
}
|
|
217
|
+
getMongoOptions(options) {
|
|
258
218
|
if (_.isUndefined(options)) {
|
|
259
219
|
return {};
|
|
260
220
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
221
|
+
let result = {};
|
|
222
|
+
let projection = this.getMongoFieldsOptions(options.fields);
|
|
223
|
+
let sort = this.getMongoSortOptions(options.sort);
|
|
264
224
|
result.projection = projection;
|
|
265
225
|
result.sort = sort;
|
|
266
226
|
result.limit = options.top;
|
|
267
227
|
result.skip = options.skip;
|
|
268
228
|
return result;
|
|
269
|
-
}
|
|
270
|
-
|
|
229
|
+
}
|
|
230
|
+
getAggregateOptions(options) {
|
|
271
231
|
if (_.isUndefined(options)) {
|
|
272
232
|
return [];
|
|
273
233
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
234
|
+
let result = [];
|
|
235
|
+
let projection = this.getMongoFieldsOptions(options.fields);
|
|
236
|
+
let sort = this.getMongoSortOptions(options.sort);
|
|
277
237
|
if (!_.isEmpty(projection)) {
|
|
278
238
|
result.push({ $project: projection });
|
|
279
239
|
}
|
|
@@ -287,345 +247,200 @@ var SteedosMongoDriver = (function () {
|
|
|
287
247
|
result.push({ $limit: options.top });
|
|
288
248
|
}
|
|
289
249
|
return result;
|
|
290
|
-
}
|
|
291
|
-
|
|
250
|
+
}
|
|
251
|
+
collection(name) {
|
|
292
252
|
if (!this._collections[name]) {
|
|
293
|
-
|
|
253
|
+
const db = this._client.db();
|
|
294
254
|
this._collections[name] = db.collection(name);
|
|
295
255
|
}
|
|
296
256
|
return this._collections[name];
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
return
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
};
|
|
405
|
-
SteedosMongoDriver.prototype.findOne = function (tableName, id, query) {
|
|
406
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
407
|
-
var collection, mongoOptions, mongoFilters, selector, result;
|
|
408
|
-
return tslib_1.__generator(this, function (_a) {
|
|
409
|
-
switch (_a.label) {
|
|
410
|
-
case 0: return [4, this.connect()];
|
|
411
|
-
case 1:
|
|
412
|
-
_a.sent();
|
|
413
|
-
collection = this.collection(tableName);
|
|
414
|
-
mongoOptions = this.getMongoOptions(query);
|
|
415
|
-
mongoFilters = this.getMongoFilters(query.filters);
|
|
416
|
-
selector = { _id: id };
|
|
417
|
-
if (_.isObject(id)) {
|
|
418
|
-
selector = this.getMongoFilters(id["filters"]);
|
|
419
|
-
}
|
|
420
|
-
if (!_.isEmpty(mongoFilters)) {
|
|
421
|
-
selector = Object.assign(mongoFilters, selector);
|
|
422
|
-
}
|
|
423
|
-
return [4, collection.findOne(selector, mongoOptions)];
|
|
424
|
-
case 2:
|
|
425
|
-
result = _a.sent();
|
|
426
|
-
return [2, result];
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
});
|
|
430
|
-
};
|
|
431
|
-
SteedosMongoDriver.prototype.insert = function (tableName, data) {
|
|
432
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
433
|
-
var collection, result;
|
|
434
|
-
return tslib_1.__generator(this, function (_a) {
|
|
435
|
-
switch (_a.label) {
|
|
436
|
-
case 0: return [4, this.connect()];
|
|
437
|
-
case 1:
|
|
438
|
-
_a.sent();
|
|
439
|
-
data._id = data._id || new mongodb_1.ObjectId().toHexString();
|
|
440
|
-
collection = this.collection(tableName);
|
|
441
|
-
return [4, collection.insertOne(data)];
|
|
442
|
-
case 2:
|
|
443
|
-
result = _a.sent();
|
|
444
|
-
return [2, result.ops[0]];
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
});
|
|
448
|
-
};
|
|
449
|
-
SteedosMongoDriver.prototype.update = function (tableName, id, data) {
|
|
450
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
451
|
-
var collection, selector, options, keys, result;
|
|
452
|
-
return tslib_1.__generator(this, function (_a) {
|
|
453
|
-
switch (_a.label) {
|
|
454
|
-
case 0:
|
|
455
|
-
if (_.isEmpty(data)) {
|
|
456
|
-
throw new Error("the params 'data' must not be empty");
|
|
457
|
-
}
|
|
458
|
-
return [4, this.connect()];
|
|
459
|
-
case 1:
|
|
460
|
-
_a.sent();
|
|
461
|
-
collection = this.collection(tableName);
|
|
462
|
-
if (_.isObject(id)) {
|
|
463
|
-
selector = this.getMongoFilters(id["filters"]);
|
|
464
|
-
}
|
|
465
|
-
else {
|
|
466
|
-
selector = { _id: id };
|
|
467
|
-
}
|
|
468
|
-
options = { $set: {}, $unset: {} };
|
|
469
|
-
keys = _.keys(data);
|
|
470
|
-
_.each(keys, function (key) {
|
|
471
|
-
if (_.include([
|
|
472
|
-
"$inc",
|
|
473
|
-
"$min",
|
|
474
|
-
"$max",
|
|
475
|
-
"$mul",
|
|
476
|
-
"$push",
|
|
477
|
-
"$addToSet",
|
|
478
|
-
"$pop",
|
|
479
|
-
"$pull",
|
|
480
|
-
"$pullAll",
|
|
481
|
-
], key)) {
|
|
482
|
-
options[key] = data[key];
|
|
483
|
-
}
|
|
484
|
-
else {
|
|
485
|
-
if (null === data[key]) {
|
|
486
|
-
options.$unset[key] = 1;
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
options.$set[key] = data[key];
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
if (_.isEmpty(options.$set)) {
|
|
494
|
-
delete options.$set;
|
|
495
|
-
}
|
|
496
|
-
if (_.isEmpty(options.$unset)) {
|
|
497
|
-
delete options.$unset;
|
|
498
|
-
}
|
|
499
|
-
return [4, collection.updateOne(selector, options)];
|
|
500
|
-
case 2:
|
|
501
|
-
result = _a.sent();
|
|
502
|
-
if (!result.result.ok) return [3, 4];
|
|
503
|
-
return [4, collection.findOne(selector)];
|
|
504
|
-
case 3:
|
|
505
|
-
result = _a.sent();
|
|
506
|
-
return [2, result];
|
|
507
|
-
case 4: return [2];
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
});
|
|
511
|
-
};
|
|
512
|
-
SteedosMongoDriver.prototype.updateOne = function (tableName, id, data) {
|
|
513
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
514
|
-
var collection, selector, result;
|
|
515
|
-
return tslib_1.__generator(this, function (_a) {
|
|
516
|
-
switch (_a.label) {
|
|
517
|
-
case 0:
|
|
518
|
-
if (_.isEmpty(data)) {
|
|
519
|
-
throw new Error("the params 'data' must not be empty");
|
|
520
|
-
}
|
|
521
|
-
return [4, this.connect()];
|
|
522
|
-
case 1:
|
|
523
|
-
_a.sent();
|
|
524
|
-
collection = this.collection(tableName);
|
|
525
|
-
if (_.isObject(id)) {
|
|
526
|
-
selector = this.getMongoFilters(id["filters"]);
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
529
|
-
selector = { _id: id };
|
|
530
|
-
}
|
|
531
|
-
return [4, collection.updateOne(selector, { $set: data })];
|
|
532
|
-
case 2:
|
|
533
|
-
result = _a.sent();
|
|
534
|
-
if (!result.result.ok) return [3, 4];
|
|
535
|
-
return [4, collection.findOne(selector)];
|
|
536
|
-
case 3:
|
|
537
|
-
result = _a.sent();
|
|
538
|
-
return [2, result];
|
|
539
|
-
case 4: return [2];
|
|
540
|
-
}
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
|
-
};
|
|
544
|
-
SteedosMongoDriver.prototype.updateMany = function (tableName, queryFilters, data) {
|
|
545
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
546
|
-
var collection, mongoFilters;
|
|
547
|
-
return tslib_1.__generator(this, function (_a) {
|
|
548
|
-
switch (_a.label) {
|
|
549
|
-
case 0:
|
|
550
|
-
if (_.isEmpty(data)) {
|
|
551
|
-
throw new Error("the params 'data' must not be empty");
|
|
552
|
-
}
|
|
553
|
-
return [4, this.connect()];
|
|
554
|
-
case 1:
|
|
555
|
-
_a.sent();
|
|
556
|
-
collection = this.collection(tableName);
|
|
557
|
-
mongoFilters = this.getMongoFilters(queryFilters);
|
|
558
|
-
return [4, collection.update(mongoFilters, { $set: data }, { multi: true })];
|
|
559
|
-
case 2: return [2, _a.sent()];
|
|
257
|
+
}
|
|
258
|
+
async find(tableName, query) {
|
|
259
|
+
await this.connect();
|
|
260
|
+
const collection = this.collection(tableName);
|
|
261
|
+
const mongoFilters = this.getMongoFilters(query.filters);
|
|
262
|
+
const mongoOptions = this.getMongoOptions(query);
|
|
263
|
+
const result = await collection.find(mongoFilters, mongoOptions).toArray();
|
|
264
|
+
return result;
|
|
265
|
+
}
|
|
266
|
+
async aggregate(tableName, query, externalPipeline) {
|
|
267
|
+
await this.connect();
|
|
268
|
+
const collection = this.collection(tableName);
|
|
269
|
+
let pipeline = [];
|
|
270
|
+
const mongoFilters = this.getMongoFilters(query.filters);
|
|
271
|
+
const aggregateOptions = this.getAggregateOptions(query);
|
|
272
|
+
pipeline.push({ $match: mongoFilters });
|
|
273
|
+
pipeline = pipeline.concat(aggregateOptions).concat(externalPipeline);
|
|
274
|
+
const result = await collection.aggregate(pipeline).toArray();
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
async directAggregate(tableName, query, externalPipeline, userId) {
|
|
278
|
+
await this.connect();
|
|
279
|
+
let collection = this.collection(tableName);
|
|
280
|
+
let pipeline = [];
|
|
281
|
+
if (query.filters) {
|
|
282
|
+
let mongoFilters = this.getMongoFilters(query.filters);
|
|
283
|
+
let aggregateOptions = this.getAggregateOptions(query);
|
|
284
|
+
pipeline.push({ $match: mongoFilters });
|
|
285
|
+
pipeline = pipeline.concat(aggregateOptions);
|
|
286
|
+
}
|
|
287
|
+
pipeline = pipeline.concat(externalPipeline);
|
|
288
|
+
let result = await collection.aggregate(pipeline).toArray();
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
async directAggregatePrefixalPipeline(tableName, query, prefixalPipeline, userId) {
|
|
292
|
+
await this.connect();
|
|
293
|
+
let collection = this.collection(tableName);
|
|
294
|
+
let pipeline = [];
|
|
295
|
+
let mongoFilters = this.getMongoFilters(query.filters);
|
|
296
|
+
let aggregateOptions = this.getAggregateOptions(query);
|
|
297
|
+
pipeline.push({ $match: mongoFilters });
|
|
298
|
+
pipeline = prefixalPipeline.concat(pipeline).concat(aggregateOptions);
|
|
299
|
+
let result = await collection.aggregate(pipeline).toArray();
|
|
300
|
+
return result;
|
|
301
|
+
}
|
|
302
|
+
async count(tableName, query) {
|
|
303
|
+
await this.connect();
|
|
304
|
+
let collection = this.collection(tableName);
|
|
305
|
+
let mongoFilters = this.getMongoFilters(query.filters);
|
|
306
|
+
let mongoOptions = this.getMongoOptions(query);
|
|
307
|
+
let result = await collection.find(mongoFilters, mongoOptions).count();
|
|
308
|
+
return result;
|
|
309
|
+
}
|
|
310
|
+
async findOne(tableName, id, query) {
|
|
311
|
+
await this.connect();
|
|
312
|
+
let collection = this.collection(tableName);
|
|
313
|
+
let mongoOptions = this.getMongoOptions(query);
|
|
314
|
+
let mongoFilters = this.getMongoFilters(query.filters);
|
|
315
|
+
let selector = { _id: id };
|
|
316
|
+
if (_.isObject(id)) {
|
|
317
|
+
selector = this.getMongoFilters(id["filters"]);
|
|
318
|
+
}
|
|
319
|
+
if (!_.isEmpty(mongoFilters)) {
|
|
320
|
+
selector = Object.assign(mongoFilters, selector);
|
|
321
|
+
}
|
|
322
|
+
let result = await collection.findOne(selector, mongoOptions);
|
|
323
|
+
return result;
|
|
324
|
+
}
|
|
325
|
+
async insert(tableName, data) {
|
|
326
|
+
await this.connect();
|
|
327
|
+
data._id = data._id || new mongodb_1.ObjectId().toHexString();
|
|
328
|
+
let collection = this.collection(tableName);
|
|
329
|
+
let result = await collection.insertOne(data);
|
|
330
|
+
return result.ops[0];
|
|
331
|
+
}
|
|
332
|
+
async update(tableName, id, data) {
|
|
333
|
+
if (_.isEmpty(data)) {
|
|
334
|
+
throw new Error("the params 'data' must not be empty");
|
|
335
|
+
}
|
|
336
|
+
await this.connect();
|
|
337
|
+
let collection = this.collection(tableName);
|
|
338
|
+
let selector;
|
|
339
|
+
if (_.isObject(id)) {
|
|
340
|
+
selector = this.getMongoFilters(id["filters"]);
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
selector = { _id: id };
|
|
344
|
+
}
|
|
345
|
+
const options = { $set: {}, $unset: {} };
|
|
346
|
+
const keys = _.keys(data);
|
|
347
|
+
_.each(keys, function (key) {
|
|
348
|
+
if (_.include([
|
|
349
|
+
"$inc",
|
|
350
|
+
"$min",
|
|
351
|
+
"$max",
|
|
352
|
+
"$mul",
|
|
353
|
+
"$push",
|
|
354
|
+
"$addToSet",
|
|
355
|
+
"$pop",
|
|
356
|
+
"$pull",
|
|
357
|
+
"$pullAll",
|
|
358
|
+
], key)) {
|
|
359
|
+
options[key] = data[key];
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
if (null === data[key]) {
|
|
363
|
+
options.$unset[key] = 1;
|
|
560
364
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
};
|
|
564
|
-
SteedosMongoDriver.prototype.delete = function (tableName, id) {
|
|
565
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
566
|
-
var collection, selector, result;
|
|
567
|
-
return tslib_1.__generator(this, function (_a) {
|
|
568
|
-
switch (_a.label) {
|
|
569
|
-
case 0: return [4, this.connect()];
|
|
570
|
-
case 1:
|
|
571
|
-
_a.sent();
|
|
572
|
-
collection = this.collection(tableName);
|
|
573
|
-
if (_.isObject(id)) {
|
|
574
|
-
selector = this.getMongoFilters(id["filters"]);
|
|
575
|
-
}
|
|
576
|
-
else {
|
|
577
|
-
selector = { _id: id };
|
|
578
|
-
}
|
|
579
|
-
return [4, collection.deleteOne(selector)];
|
|
580
|
-
case 2:
|
|
581
|
-
result = _a.sent();
|
|
582
|
-
return [2, result === null || result === void 0 ? void 0 : result.deletedCount];
|
|
365
|
+
else {
|
|
366
|
+
options.$set[key] = data[key];
|
|
583
367
|
}
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
};
|
|
587
|
-
SteedosMongoDriver.prototype.directFind = function (tableName, query) {
|
|
588
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
589
|
-
return tslib_1.__generator(this, function (_a) {
|
|
590
|
-
return [2, this.find(tableName, query)];
|
|
591
|
-
});
|
|
592
|
-
});
|
|
593
|
-
};
|
|
594
|
-
SteedosMongoDriver.prototype.directInsert = function (tableName, data) {
|
|
595
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
596
|
-
return tslib_1.__generator(this, function (_a) {
|
|
597
|
-
return [2, this.insert(tableName, data)];
|
|
598
|
-
});
|
|
599
|
-
});
|
|
600
|
-
};
|
|
601
|
-
SteedosMongoDriver.prototype.directUpdate = function (tableName, id, data) {
|
|
602
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
603
|
-
return tslib_1.__generator(this, function (_a) {
|
|
604
|
-
return [2, this.update(tableName, id, data)];
|
|
605
|
-
});
|
|
606
|
-
});
|
|
607
|
-
};
|
|
608
|
-
SteedosMongoDriver.prototype.directDelete = function (tableName, id) {
|
|
609
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
610
|
-
return tslib_1.__generator(this, function (_a) {
|
|
611
|
-
return [2, this.delete(tableName, id)];
|
|
612
|
-
});
|
|
613
|
-
});
|
|
614
|
-
};
|
|
615
|
-
SteedosMongoDriver.prototype.directUpdateMany = function (tableName, queryFilters, data) {
|
|
616
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
617
|
-
return tslib_1.__generator(this, function (_a) {
|
|
618
|
-
return [2, this.updateMany(tableName, queryFilters, data)];
|
|
619
|
-
});
|
|
368
|
+
}
|
|
620
369
|
});
|
|
621
|
-
|
|
622
|
-
|
|
370
|
+
if (_.isEmpty(options.$set)) {
|
|
371
|
+
delete options.$set;
|
|
372
|
+
}
|
|
373
|
+
if (_.isEmpty(options.$unset)) {
|
|
374
|
+
delete options.$unset;
|
|
375
|
+
}
|
|
376
|
+
let result = await collection.updateOne(selector, options);
|
|
377
|
+
if (result.result.ok) {
|
|
378
|
+
result = await collection.findOne(selector);
|
|
379
|
+
return result;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
async updateOne(tableName, id, data) {
|
|
383
|
+
if (_.isEmpty(data)) {
|
|
384
|
+
throw new Error("the params 'data' must not be empty");
|
|
385
|
+
}
|
|
386
|
+
await this.connect();
|
|
387
|
+
let collection = this.collection(tableName);
|
|
388
|
+
let selector;
|
|
389
|
+
if (_.isObject(id)) {
|
|
390
|
+
selector = this.getMongoFilters(id["filters"]);
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
selector = { _id: id };
|
|
394
|
+
}
|
|
395
|
+
let result = await collection.updateOne(selector, { $set: data });
|
|
396
|
+
if (result.result.ok) {
|
|
397
|
+
result = await collection.findOne(selector);
|
|
398
|
+
return result;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
async updateMany(tableName, queryFilters, data) {
|
|
402
|
+
if (_.isEmpty(data)) {
|
|
403
|
+
throw new Error("the params 'data' must not be empty");
|
|
404
|
+
}
|
|
405
|
+
await this.connect();
|
|
406
|
+
let collection = this.collection(tableName);
|
|
407
|
+
let mongoFilters = this.getMongoFilters(queryFilters);
|
|
408
|
+
return await collection.update(mongoFilters, { $set: data }, { multi: true });
|
|
409
|
+
}
|
|
410
|
+
async delete(tableName, id) {
|
|
411
|
+
await this.connect();
|
|
412
|
+
let collection = this.collection(tableName);
|
|
413
|
+
let selector;
|
|
414
|
+
if (_.isObject(id)) {
|
|
415
|
+
selector = this.getMongoFilters(id["filters"]);
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
selector = { _id: id };
|
|
419
|
+
}
|
|
420
|
+
const result = await collection.deleteOne(selector);
|
|
421
|
+
return result?.deletedCount;
|
|
422
|
+
}
|
|
423
|
+
async directFind(tableName, query) {
|
|
424
|
+
return this.find(tableName, query);
|
|
425
|
+
}
|
|
426
|
+
async directInsert(tableName, data) {
|
|
427
|
+
return this.insert(tableName, data);
|
|
428
|
+
}
|
|
429
|
+
async directUpdate(tableName, id, data) {
|
|
430
|
+
return this.update(tableName, id, data);
|
|
431
|
+
}
|
|
432
|
+
async directDelete(tableName, id) {
|
|
433
|
+
return this.delete(tableName, id);
|
|
434
|
+
}
|
|
435
|
+
async directUpdateMany(tableName, queryFilters, data) {
|
|
436
|
+
return this.updateMany(tableName, queryFilters, data);
|
|
437
|
+
}
|
|
438
|
+
_makeNewID(tableName) {
|
|
623
439
|
return new mongodb_1.ObjectId().toHexString();
|
|
624
|
-
}
|
|
625
|
-
|
|
440
|
+
}
|
|
441
|
+
formatRecord(doc, objectConfig) {
|
|
626
442
|
return (0, format_1.formatRecord)(doc, objectConfig);
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
}());
|
|
443
|
+
}
|
|
444
|
+
}
|
|
630
445
|
exports.SteedosMongoDriver = SteedosMongoDriver;
|
|
631
446
|
//# sourceMappingURL=mongo.js.map
|