【发布时间】:2021-11-17 21:16:41
【问题描述】:
我有一个带有主键地址的数据库
| Address | other values...|
| ----------------------| -------------- |
| ed.nl | null |
| spelletjes.nl | null |
| kinderspelletjes.nl | null |
我想编写一个请求,删除与我在数组中传递的地址匹配的行。
我的 missing-urls.js 文件中有这个
async function deleteMissingUrls(request, reply) {
try {
const addresses = request.body;
const { rows } = await pg.query(formatQry.deleteByAddress, [addresses]);
reply.send({
total: rows.length,
items: rows,
});
} catch (err) {
log.error(`Error while deleting. ${err.message}`);
reply.internalServerError(err.message);
}
}
并在我的 query/missing-urls.js 文件中使用此查询
export const deleteByAddress = 'DELETE FROM metrics.missing_url WHERE address IN (?)';
当我运行这个请求时
curl -X DELETE -d '["ed.nl", "spelletjes.nl"]' -H "Content-Type: application/json" http://localhost:3000/api/missing/urls
我遇到了一个错误。
{"statusCode":500,"error":"Internal Server Error","message":"syntax error at or near \")\""}%
我做错了什么?
【问题讨论】:
-
看起来您正在发送一个数组作为数据,然后在 query 调用中将该数组作为一个元素包含在另一个数组中。
标签: sql node.js postgresql curl