“错误:绑定消息提供了1个参数,但是准备好的语句“”要求为0”不知道其含义或解决方法
我正在上数据库课程,并在尝试运行程序时收到该错误。
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
app.set("port", 8080);
app.use(bodyParser.json({ type: "application/json" }));
app.use(bodyParser.urlencoded({ extended: true }));
const Pool = require("pg").Pool;
const config = {
host: "localhost",
user: "me",
password: "64594640",
database: "new"
};
const pool = new Pool(config);
//say hello
app.get("/hello", (req,res) => {
res.json("Hello world!");
});
app.get("/workshop", async (req,res) => {
try {
// find workshops
const template = "SELECT workshop FROM people";
const responce = await pool.query(template, [req.query.q]);
console.log(response);
} catch (err) {
console.log("whoops " + err);
}
});
app.listen(app.get("port"), () => {
console.log(`Find the server at: http://localhost:${app.get("port")}/`);
});
我正在节点上运行该程序,并且拥有我自己的所有者一个新的postgresql数据库。
回答如下:您为query
方法提供了一个参数:
req.query.q
因此该方法搜索将此参数放入SELECT workshop FROM people
查询中的位置。
找不到占位符$1
替换为参数req.query.q
。您要么忘记在查询中添加一些参数,要么不需要向其传递任何参数。
要查看有关带参数的query
方法的更多信息,请参见示例:https://node-postgres/features/queries#Parameterized%20query
“错误:绑定消息提供了1个参数,但是准备好的语句“”要求为0”不知道其含义或解决方法
我正在上数据库课程,并在尝试运行程序时收到该错误。
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
app.set("port", 8080);
app.use(bodyParser.json({ type: "application/json" }));
app.use(bodyParser.urlencoded({ extended: true }));
const Pool = require("pg").Pool;
const config = {
host: "localhost",
user: "me",
password: "64594640",
database: "new"
};
const pool = new Pool(config);
//say hello
app.get("/hello", (req,res) => {
res.json("Hello world!");
});
app.get("/workshop", async (req,res) => {
try {
// find workshops
const template = "SELECT workshop FROM people";
const responce = await pool.query(template, [req.query.q]);
console.log(response);
} catch (err) {
console.log("whoops " + err);
}
});
app.listen(app.get("port"), () => {
console.log(`Find the server at: http://localhost:${app.get("port")}/`);
});
我正在节点上运行该程序,并且拥有我自己的所有者一个新的postgresql数据库。
回答如下:您为query
方法提供了一个参数:
req.query.q
因此该方法搜索将此参数放入SELECT workshop FROM people
查询中的位置。
找不到占位符$1
替换为参数req.query.q
。您要么忘记在查询中添加一些参数,要么不需要向其传递任何参数。
要查看有关带参数的query
方法的更多信息,请参见示例:https://node-postgres/features/queries#Parameterized%20query