问题
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