js and Postgres (using this module) and I would like to view the SQL that has been executed after I have queried the database (as I'm using parameterised statements). Is there an easy way to do this?
For example, I execute code as follows:
var first = client.query("UPDATE settings SET json=$1 WHERE source_name=$2", [JSON.stringify(settings), 'website']);
first.on('end', function(result){
console.log(result);
client.end();
});
Is there a method like result.lastQuery()
that I can utilise as I can't find anything like this in the docs? I'm having trouble getting my query to work and I'd like to debug it further.
There appears to be no direct way to do this (if Postgres is like most database servers, the query, with parameter markers, is compiled into intermediate code and the actual parameters are bound later on, so there's never any actual SQL text with the parameter values interpolated into it).
This blog post might or might not be helpful.