是否有更好的方法使用 pg 插入未定义为 null 的变量
const pg = require('pg');
a = a? a: null // hope to remove this line
b = b? b: null // hope to remove this line
c = c? c: null // hope to remove this line
client.query('INSERT INTO abc(a,b,c) VALUES($1,$2,$3)', [a,b,c], function(err, result) {
//do something here
})
这样就不必检查每个变量并用“”替换之前的未定义
最佳答案
您可以使用 || 定义 undefined variable 运算符(operator)。 例如
var a ;
var b = a || null;
关于javascript - 如何为pg Node js插入未定义的值作为null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44666692/