plugin-data-source-mssql 2.0.1 → 2.0.3
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/dist/externalVersion.js
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "2.0.
|
|
12
|
-
"@nocobase/plugin-data-source-manager": "2.0.
|
|
13
|
-
"@nocobase/server": "2.0.
|
|
14
|
-
"@nocobase/database": "2.0.
|
|
11
|
+
"@nocobase/client": "2.0.15",
|
|
12
|
+
"@nocobase/plugin-data-source-manager": "2.0.15",
|
|
13
|
+
"@nocobase/server": "2.0.15",
|
|
14
|
+
"@nocobase/database": "2.0.15",
|
|
15
15
|
"react": "18.2.0",
|
|
16
16
|
"@formily/react": "2.3.7",
|
|
17
17
|
"antd": "5.24.2",
|
|
@@ -19,8 +19,8 @@ module.exports = {
|
|
|
19
19
|
"@ant-design/icons": "5.6.1",
|
|
20
20
|
"@emotion/css": "11.13.0",
|
|
21
21
|
"react-router-dom": "6.30.1",
|
|
22
|
-
"@nocobase/actions": "2.0.
|
|
23
|
-
"@nocobase/data-source-manager": "2.0.
|
|
22
|
+
"@nocobase/actions": "2.0.15",
|
|
23
|
+
"@nocobase/data-source-manager": "2.0.15",
|
|
24
24
|
"sequelize": "6.35.2",
|
|
25
25
|
"lodash": "4.17.21"
|
|
26
26
|
};
|
|
@@ -181,79 +181,34 @@ class MssqlExternalDataSource extends import_data_source_manager.SequelizeDataSo
|
|
|
181
181
|
}
|
|
182
182
|
/**
|
|
183
183
|
* Set up MSSQL-specific Sequelize hooks for datetime handling.
|
|
184
|
-
* MSSQL DATETIME doesn't support timezone offset format like '+00:00'
|
|
184
|
+
* MSSQL DATETIME doesn't support timezone offset format like '+00:00',
|
|
185
|
+
* so we convert Date objects to 'YYYY-MM-DD HH:mm:ss.SSS' on save.
|
|
186
|
+
*
|
|
187
|
+
* NOTE: We intentionally do NOT transform dates in WHERE clauses.
|
|
188
|
+
* The NocoBase core date operators already produce properly formatted strings
|
|
189
|
+
* (via DatetimeNoTzField → 'YYYY-MM-DD HH:mm:ss') that MSSQL understands
|
|
190
|
+
* natively. Using Sequelize.literal() for dates in WHERE clauses would:
|
|
191
|
+
* 1. Bypass parameterized queries → no index usage → full table scans
|
|
192
|
+
* 2. Add recursive overhead to every single query
|
|
185
193
|
*/
|
|
186
194
|
setupMssqlHooks() {
|
|
187
195
|
const db = this.collectionManager.db;
|
|
188
196
|
if (!(db == null ? void 0 : db.sequelize)) return;
|
|
189
|
-
const Sequelize = db.sequelize.Sequelize;
|
|
190
|
-
if (!Sequelize) return;
|
|
191
|
-
db.sequelize.addHook("afterConnect", (connection) => {
|
|
192
|
-
if (connection && typeof connection.execSql === "function") {
|
|
193
|
-
try {
|
|
194
|
-
const { Request } = require("tedious");
|
|
195
|
-
connection.execSql(new Request("SET NOCOUNT ON", () => {
|
|
196
|
-
}));
|
|
197
|
-
} catch {
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
197
|
const isDatetimeString = (value) => {
|
|
202
198
|
return /^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}(:\d{2})?)?$/.test(value);
|
|
203
199
|
};
|
|
204
200
|
db.sequelize.addHook("beforeSave", (instance) => {
|
|
205
|
-
if (instance
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
dateValue = new Date(value);
|
|
213
|
-
}
|
|
214
|
-
if (dateValue && !isNaN(dateValue.getTime())) {
|
|
215
|
-
const iso = dateValue.toISOString();
|
|
216
|
-
const mssqlDate = iso.replace("T", " ").replace("Z", "");
|
|
217
|
-
if (Sequelize && Sequelize.literal) {
|
|
218
|
-
instance.dataValues[key] = Sequelize.literal(`'${mssqlDate}'`);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
201
|
+
if (!(instance == null ? void 0 : instance.dataValues)) return;
|
|
202
|
+
for (const [key, value] of Object.entries(instance.dataValues)) {
|
|
203
|
+
let dateValue = null;
|
|
204
|
+
if (value instanceof Date) {
|
|
205
|
+
dateValue = value;
|
|
206
|
+
} else if (typeof value === "string" && isDatetimeString(value)) {
|
|
207
|
+
dateValue = new Date(value);
|
|
221
208
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const transformDatesInObject = (obj, Sq) => {
|
|
225
|
-
if (!obj || typeof obj !== "object") return obj;
|
|
226
|
-
if (obj instanceof Date) {
|
|
227
|
-
if (!isNaN(obj.getTime())) {
|
|
228
|
-
const iso = obj.toISOString();
|
|
229
|
-
const mssqlDate = iso.replace("T", " ").replace("Z", "");
|
|
230
|
-
return Sq.literal(`'${mssqlDate}'`);
|
|
209
|
+
if (dateValue && !isNaN(dateValue.getTime())) {
|
|
210
|
+
instance.dataValues[key] = dateValue.toISOString().replace("T", " ").replace("Z", "");
|
|
231
211
|
}
|
|
232
|
-
return obj;
|
|
233
|
-
}
|
|
234
|
-
if (Array.isArray(obj)) {
|
|
235
|
-
return obj.map((item) => transformDatesInObject(item, Sq));
|
|
236
|
-
}
|
|
237
|
-
const result = {};
|
|
238
|
-
for (const key of Reflect.ownKeys(obj)) {
|
|
239
|
-
result[key] = transformDatesInObject(obj[key], Sq);
|
|
240
|
-
}
|
|
241
|
-
return result;
|
|
242
|
-
};
|
|
243
|
-
db.sequelize.addHook("beforeFind", (options) => {
|
|
244
|
-
if (!options || !options.where) return;
|
|
245
|
-
try {
|
|
246
|
-
options.where = transformDatesInObject(options.where, Sequelize);
|
|
247
|
-
} catch (err) {
|
|
248
|
-
console.error("[MSSQL] Error transforming dates in WHERE:", err);
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
db.sequelize.addHook("beforeCount", (options) => {
|
|
252
|
-
if (!options || !options.where) return;
|
|
253
|
-
try {
|
|
254
|
-
options.where = transformDatesInObject(options.where, Sequelize);
|
|
255
|
-
} catch (err) {
|
|
256
|
-
console.error("[MSSQL] Error transforming dates in WHERE:", err);
|
|
257
212
|
}
|
|
258
213
|
});
|
|
259
214
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"displayName": "Data source: MSSQL",
|
|
4
4
|
"displayName.ru-RU": "Источник данных: MSSQL",
|
|
5
5
|
"displayName.zh-CN": "数据源:MSSQL",
|
|
6
|
-
"version": "2.0.
|
|
6
|
+
"version": "2.0.3",
|
|
7
7
|
"description": "External MSSQL data source support for NocoBase.",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"main": "./dist/server/index.js",
|