How to Increase counts in database using javascript increment method?

笑着哭i 提交于 2021-01-29 18:04:24

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/64182742/how-to-increase-counts-in-database-using-javascript-increment-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!