所以我有此功能来插入数据:
const Pool = require('pg').Pool;
const pool = new Pool({
user: 'postgres',
host: 'localhost',
database: 'self_learning',
password: 'password',
port: 5432,
});
const createCategory = async (req, res) => {
const {name, parent} = req.body;
pool.
query('INSERT INTO categories ' +
'(name, parent) ' +
'VALUES ($1, $2)', [name, parent])
.then(ponse => console.log(ponse.rows[0]))
.catch(error => console.error(error.stack))
};
,但是then
语句中的值返回为undefined,尽管查询已成功执行。
我正在使用“ pg”库连接到数据库