javascript - 如何为pg Node js插入未定义的值作为null

标签 javascript node.js postgresql

是否有更好的方法使用 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/

相关文章:

Javascript:实现 100% 防篡改私有(private)变量的方法?

postgresql - 值不在ssis的预期范围内……嗯?

PostgreSQL 触发器不返回任何内容

javascript - Ionic Angular 元素中未加载样式表

javascript - AngularJS:在JSP中获取$http.post数据

javascript - 正则表达式模式中的可选子字符串

node.js - 使用 NodeJS 存储 x 小时的数据

node.js - NodeJS CloudFront createInvalidation 的示例语法

javascript - 如何查看Google Drive API的文件和文件夹?

Django + PostgreSQL : Fill missing dates in a range