I want to make sure this isn't a user error before creating a bug report
Using sails-postgresql
adapter I have a query (I've dummied down for purposes of this question) that wants to handle a NULL value, but I get an error no matter how I write the query. I've tried different variations of it, but you should get the jist of what I want to do here:
parent = req.param('parent') or null
Route.query 'SELECT * FROM route WHERE parent '+(if not parent then 'is' else '=')+' $1', [parent], (err, routes)->
console.log(err, routes)
if err
return res.json(400, [error: sails.__('Database.connect'), _error: err])
res.json(routes.rows)
Some variation of the above where I'm always passing in data will always error out.
A simple fix is
parent = req.param('parent') or null
values = []
if(parent)
values.unshift(parent)
Route.query 'SELECT * FROM route WHERE parent '+(if not parent then 'is NULL' else '= $1'), values, (err, routes)->
Which is just kind of a nuisance.
Is there a better way to do that? I have to assume this raw query is making a postgres prepared statement so perhaps it's how postgres is actually handling the null. I haven't dug much into the source to see what is going on yet.