使用 knex.js 更新 postgresql 列失败
Unsuccessfully updating postgresql columns with knex.js
在更新时遇到非常奇怪的问题,我没有收到任何响应,没有错误,没有警告,也没有成功消息,基本上没有任何变化,但请求永无止境(总是加载...)。我正在使用 knex.js 进行查询。所以基本上我正在做非常简单的补丁请求,通过选择的选项从 table 更新一些属性。
我有路由器:
const express = require("express");
const router = express.Router();
router
.route("/client/:id")
.get(getSingleClientController)
.patch([updateClientMiddleware], updateClientController);
module.exports = router;
为了在中间件中进行测试,我只有 next(),这意味着实际上它会立即通过它。 controller基本上就是调用服务,整个逻辑在哪里。
服务:
const {createClientDao, getAllClientsDao, getSingleClientDao, updateClientDao} = require("../dao/adminDao");
const updateClientService = async (Request) => {
const {id} = Request.params;
const singleClient = await getSingleClientDao("client_id", id);
if (singleClient.length <= 0) return {message: `Client with id ${id} does not exists`};
const {client_name, client_vat, client_email} = Request.body;
const clientUpdatePayload = {
client_name: client_name ? client_name : singleClient[0].client_name,
client_vat: client_vat ? client_vat : singleClient[0].client_vat,
client_email: client_email ? client_email : singleClient[0].client_email
};
const response = await updateClientDao("client_id", id, clientUpdatePayload);
// nothing comes here
console.log(response);
};
道:
const updateClientDao = async (property, value, payload) => {
return database("clients")
.where(property, value)
.update(payload);
};
我几乎到处调试,负载正常,一切正常,没有未定义或空值。 属性,dao 函数的值也随之而来。附加客户端 table
似乎迁移出现了问题,进行了回滚,现在工作正常。代码正确
在更新时遇到非常奇怪的问题,我没有收到任何响应,没有错误,没有警告,也没有成功消息,基本上没有任何变化,但请求永无止境(总是加载...)。我正在使用 knex.js 进行查询。所以基本上我正在做非常简单的补丁请求,通过选择的选项从 table 更新一些属性。
我有路由器:
const express = require("express");
const router = express.Router();
router
.route("/client/:id")
.get(getSingleClientController)
.patch([updateClientMiddleware], updateClientController);
module.exports = router;
为了在中间件中进行测试,我只有 next(),这意味着实际上它会立即通过它。 controller基本上就是调用服务,整个逻辑在哪里。
服务:
const {createClientDao, getAllClientsDao, getSingleClientDao, updateClientDao} = require("../dao/adminDao");
const updateClientService = async (Request) => {
const {id} = Request.params;
const singleClient = await getSingleClientDao("client_id", id);
if (singleClient.length <= 0) return {message: `Client with id ${id} does not exists`};
const {client_name, client_vat, client_email} = Request.body;
const clientUpdatePayload = {
client_name: client_name ? client_name : singleClient[0].client_name,
client_vat: client_vat ? client_vat : singleClient[0].client_vat,
client_email: client_email ? client_email : singleClient[0].client_email
};
const response = await updateClientDao("client_id", id, clientUpdatePayload);
// nothing comes here
console.log(response);
};
道:
const updateClientDao = async (property, value, payload) => {
return database("clients")
.where(property, value)
.update(payload);
};
我几乎到处调试,负载正常,一切正常,没有未定义或空值。 属性,dao 函数的值也随之而来。附加客户端 table
似乎迁移出现了问题,进行了回滚,现在工作正常。代码正确