From 13c101a4514119044b39fbe5ba1db036b4962f9b Mon Sep 17 00:00:00 2001 From: "luk.lu" Date: Sat, 23 Jul 2022 13:04:16 +0800 Subject: [PATCH] u --- coretool.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/coretool.js b/coretool.js index e417d55..bbfeb31 100644 --- a/coretool.js +++ b/coretool.js @@ -20,21 +20,22 @@ module.exports = { let newObj = {} if (schemaColumns) { for (let key in schemaColumns) { - if (schemaColumns.hasOwnProperty(key) && !schemaColumns[key].hashExclusive && !excludeKeys.includes(key)) { - // JSON.stringify (包括本函数)会把 NaN 或 Infinity 输出为 null,会把 undefined 忽略掉。 - // 而在 typeorm sqlite 数据库中,undefined 会自动存为 schemaColumns[key].default 或 null。从数据库读出时,就会和事先JSON.stringify的结果不一致。 - // 为了和 torm 数据库保持一致习惯,对schemaColumns里的键值应当把 undefined 也设为 default 或 null。 - if (obj[key] === undefined || Number.isNaN(obj[key]) || obj[key] === Infinity) { - newObj[key] = typeof schemaColumns[key].default === 'undefined' ? null : schemaColumns[key].default - obj[key] = newObj[key] // 确保内存中的数据和数据库保持一致 - } else { - newObj[key] = obj[key] - } + // JSON.stringify (包括本函数)会把 NaN 或 Infinity 输出为 null,会把 undefined 忽略掉。 + // 而在 typeorm sqlite 数据库中,undefined 会自动存为 schemaColumns[key].default 或 null。从数据库读出时,就会和事先JSON.stringify的结果不一致。 + // 为了和 torm 数据库保持一致习惯,对schemaColumns里的键值应当把 undefined 也设为 default 或 null。 + if (obj[key] === undefined || Number.isNaN(obj[key]) || obj[key] === Infinity) { + newObj[key] = typeof schemaColumns[key].default === 'undefined' ? null : schemaColumns[key].default + obj[key] = newObj[key] // 确保内存中的数据和数据库保持一致 + } else { + newObj[key] = obj[key] } } } else { newObj = obj } + for (let exkey of excludeKeys) { + delete newObj[exkey] + } /* 以下代码来自 https://github.com/substack/json-stable-stringify 可把嵌套的复杂值也按顺序输出,例如 { c: 8, b: [{z:6,y:5,x:4},7], a: 3 } */ if (typeof space === 'number') space = Array(space + 1).join(' ')