Answers for "how update any database value in knex"

0

how update any database value in knex

router.put('/:id', async (req, res) => {
  const {id} = req.params;
  const changes = req.body;

  try {
    const count = await db('posts').where({id}).update(changes);
    if (count) {
      res.status(200).json({updated: count})
    } else {
      res.status(404).json({message: "Record not found"})
    }
  } catch (err) {
    res.status(500).json({message: "Error updating new post", error: err})
  }

});
Posted by: Guest on April-20-2021

Code answers related to "how update any database value in knex"

Browse Popular Code Answers by Language