我想在数据库中以HTML文件显示我在数据库中拥有的其他人,以便可以在网页中看到它。我将HTML字段与server.js文件连接起来没有问题!
我已经尝试对输出数据库查询的函数进行编码
const { Client } = require('pg');
const client = new Client({
host: 'localhost',
database: 'castle',
password: '123',
user: 'king',
port: 5432
})
const QUERY = `
select first_name, last_name, fav_color
from persons
where age >= 20;`
console.log('Connecting to db...');
client.connect()
.then(() => client.query(QUERY))
.then(result => {
console.log('Received result..');
result.rows.forEach(row => console.log(row));
})
.catch(err=> console.error(err))
.finally(() => client.end())
我已经在一个对象中收到了我要求的人员:
Object {first_name: "Mark", last_name: "Ruffalo", fav_color: "green"}
...