我正在尝试与knex一起检索一些数据库值,但是无论我使用什么配置,我都会得到一个500
错误代码,或者只是一个未决的网络会话。为了使它变得尽可能简单,至少可以正常工作,我编写了以下内容:
export default () => (async (req, res, knex) => {
const temp = knex('vouchers').select();
console.log(temp);
res.response(201).end();
});
根据我的理解,应该进入vouchers
表并检索所有内容,最终我只会得到500 error
和控制台日志vouchers
,即我的表名... < / p>
答案 0 :(得分:2)
尝试:
export default () => (async (req, res, knex) => {
const temp = await knex('vouchers');
console.log(temp);
res.send(JSON.stringify(temp,null,2));
});
答案 1 :(得分:0)
仅供参考:
我的解决方案基本上是重新组织查询的开始:
export default function ({ pool, queue, knex }) {
return async (req, res, next) => {
try {
const { eventId, voucher } = req.params;