问题描述
我的数据库中有一个名为 ads_counter
的字段,每次展示此广告时,我都需要增加其值.
我想在节点单击api中实现javascript的增量功能,当用户单击时,我将在请求中获得 1
,而我在数据库中将 1
增加了no.例如,如果我有 ads_counter = 5
,并且我从客户端获得了要求,则将no增加 1
.所以,我怎么增加不.数据库中 ads_counter
的数量.我不知道从哪里开始,我在Postgres数据库中使用Sequelize.请给我建议做这个建议的好方法.
我想我的答案我必须在我的节点api中添加以下代码,我必须从客户端获取 product_id
此api将使 ads_counter
增加1.
Product.update({ads_counter:sequelize.literal('ads_counter + 1')},{其中:{id:req.body.id}});
这是git问题的链接,>
I have field called ads_counter
in my database, and I need to increase its value each time when this ad is rendered.
I want to implement increment function of javascript in node rest api when be clicked by users I will get 1
in request I have increase no in database by 1
. for example If I have ads_counter = 5
and I get req from client side to increase no by 1
. so, how can I increase no. of ads_counter
in database. I'm not able to understand from where to start I am using Sequelize with postgres database. please suggest me good method to do this opreation.
I think I got The answer I have to add below code in my node api I have to get product_id
from the client side and this api will increase the ads_counter
by 1.
Product.update({ ads_counter: sequelize.literal('ads_counter+ 1') }, { where: { id: req.body.id } });
this is the link of git issue from where I got my answer
这篇关于如何使用javascript增量方法增加数据库中的计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!