gpt4 book ai didi

node.js - node js sequelize where条件如果不等于 checkin

转载 作者:行者123 更新时间:2023-12-03 22:18:40 29 4
gpt4 key购买 nike

我已经在 updateBrand 函数中更新了品牌详细信息。更新详细信息时,我检查了名称重复,但未检查相同的 ID。

(i.e) select * from "brand"where brand_name = $brand_name AND id <> $bid;

在我写的nodejs中

let duplicateData = await Brand.findOne({ where:searchQuery});

请告诉我们如何在 nodejs sequelize 查询中使用“<>”(不等于)。

品牌 Controller .js
updateBrand: async (request, h) => {
try {
let bid = request.query.id;
let searchQuery = {};
searchQuery.id = bid;
let {
brand_name,
brand_image,
description,
colorshead,
colorsbg,
brand_id,
status,
activedate,
expirydate,
} = request.payload;
///check name already exists
searchQuery.brand_name = brand_name;
let duplicateData = await Brand.findOne({ where: searchQuery });
if (!duplicateData) {
let updateBrand = await Brand.update(
{
brand_name: brand_name,
brand_image: brand_image,
colorshead: colorshead,
colorsbg: colorsbg,
brand_id: brand_id,
},
{
where: {
id: bid,
},
},
);
let response = {
statusCode: 200,
message: message.DATAFOUND,
};
return h.response(response).code(200);
} else {
return Boom.badRequest(message.NAMEEXISTS);
}
} catch (err) {
return Boom.badRequest(err.message);
}
},

最佳答案

您可以将 $ne 用于 <> :

where: {
id: { $ne : bid },
}

了解更多 Operators

关于node.js - node js sequelize where条件如果不等于 checkin ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52714481/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com