【发布时间】:2017-09-30 16:25:35
【问题描述】:
在 db/index.js 中:
const { Pool } = require('pg'); //node-postgres
const pool = new Pool;
module.exports = {
query: (text, params, callback) => {
return pool.query(text,params,callback);
}
};
在我的 main.js 中:
const db = require('./db/index');
db.query('SELECT count(*) from pg_class where relname ="session" and relkind="r"', (err, res) => {
if (err) {
//TODO: What to do if there is an error?
}
console.log(res);
});
输出是:
未定义
如何检查名称为“session”的表是否存在?我怎么知道我的查询是否有效?
编辑:这不是上述问题的重复,因为我的问题与 Node.js javascript 代码有关。不是 SQL!我只想知道在 res 对象中寻找什么,因为它似乎是未定义的......
【问题讨论】:
-
大声喊她的名字,如果得到回答 - 桌子就在那里。
-
建议您编辑标题,因为它具有误导性。
标签: node.js postgresql node-postgres