'Lower the variable without impact database variable

I would like to know if it is possible to lower the quantity without touching the database because here I would like the quantity variable to decrease but without updating the database. Indeed, the variable remains constant and does not reach zero if I do not update in the database with each click of the button.

Here is my code :

 db.query("SELECT * FROM articles WHERE id_article = ?",
          [[req.articleId]],
          function (err, result) {
              if (err) throw err;

              let quantity = result[0].quantite - 1;
              if (result[0].quantite < 1) {
              } else {
                  db.query("UPDATE articles SET quantite = ? WHERE id_article = ?", [quantity, req.articleId], function (err, result) { // I want to know if it's possible to make that without directly update the database...
                      if (err) throw err;
                  })

                  let token = req.headers['x-access-token'] || req.headers['authorization'] || req.cookies.token;

                  db.query("SELECT quantite FROM panier_item WHERE id_article = ? AND id_user = ?", [req.articleId, parseJwt(token).userId], function (err, result) {
                      if (err) throw err;
                      console.log(result[0])
                      if (result[0] === undefined) {
                          db.query("INSERT INTO panier_item(id_article,id_user,quantite) VALUES (?)", [[req.articleId, parseJwt(token).userId, 1]], function (err, result) {
                              if (err) throw err;
                          })
                      } else {
                          db.query("UPDATE panier_item SET quantite = ? WHERE id_article = ? AND id_user = ?", [result[0].quantite + 1, req.articleId, parseJwt(token).userId], function (err, result) {
                              if (err) throw err;
                          })
                      }
                  })
              }

Thanks you everyone,



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source