js和Postgres(使用这个模块),我想查看在查询数据库后执行的SQL(因为我正在使用参数化语句)。 是否有捷径可寻?
例如,我按如下方式执行代码:
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(); });有没有像result.lastQuery()这样的方法可以利用,因为我在文档中找不到这样的东西? 我无法让我的查询工作,我想进一步调试它。
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.
最满意答案
似乎没有直接的方法可以做到这一点(如果Postgres像大多数数据库服务器一样,带有参数标记的查询被编译成中间代码,实际参数稍后被绑定,所以从来没有任何带参数的实际SQL文本内插的值)。
此博客文章可能有用,也可能没用。
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.
更多推荐
发布评论