small bugfix
This commit is contained in:
		
							parent
							
								
									69b319c36e
								
							
						
					
					
						commit
						4a99b5facc
					
				@ -24,10 +24,10 @@ module.exports = {
 | 
				
			|||||||
        if (schemaColumns.hasOwnProperty(key) && ! schemaColumns[key].hashExclusive && ! excludeKeys.includes(key)) {
 | 
					        if (schemaColumns.hasOwnProperty(key) && ! schemaColumns[key].hashExclusive && ! excludeKeys.includes(key)) {
 | 
				
			||||||
          // JSON.stringify (包括本函数)会把 NaN 或 Infinity 输出为 null,会把 undefined 忽略掉。
 | 
					          // JSON.stringify (包括本函数)会把 NaN 或 Infinity 输出为 null,会把 undefined 忽略掉。
 | 
				
			||||||
          // 而在 typeorm sqlite 数据库中,undefined 会自动存为 schemaColumns[key].default 或 null。从数据库读出时,就会和事先JSON.stringify的结果不一致。
 | 
					          // 而在 typeorm sqlite 数据库中,undefined 会自动存为 schemaColumns[key].default 或 null。从数据库读出时,就会和事先JSON.stringify的结果不一致。
 | 
				
			||||||
          // 为了和数据库保持一致习惯,对schemaColumns里的键值最好把 undefined 也设为 default 或 null。
 | 
					          // 为了和 torm 数据库保持一致习惯,对schemaColumns里的键值应当把 undefined 也设为 default 或 null。
 | 
				
			||||||
          if (obj[key] === undefined || Number.isNaN(obj[key]) || obj[key] === Infinity) {
 | 
					          if (obj[key] === undefined || Number.isNaN(obj[key]) || obj[key] === Infinity) {
 | 
				
			||||||
            newObj[key] = schemaColumns[key].default || null
 | 
					            newObj[key] = typeof schemaColumns[key].default === 'undefined' ? null : schemaColumns[key].default
 | 
				
			||||||
            obj[key] = schemaColumns[key].default || null // 确保内存中的数据和数据库保持一致
 | 
					            obj[key] = newObj[key] // 确保内存中的数据和数据库保持一致
 | 
				
			||||||
          }else {
 | 
					          }else {
 | 
				
			||||||
            newObj[key] = obj[key]
 | 
					            newObj[key] = obj[key]
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user