Is there a better method of inserting a variable that is undefined as null using pg
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
})
so that don't have to check every variable and substitute "" for undefined before
you can define a undefined variable using || operator. Ex
var a ;
var b = a || null;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With