title: knex.js - simpler way to update data
body: <p>I want to update a table called client. The following code works for valid id's but for invalid ones it just hangs without calling the catch function.</p>
  
  <pre><code>knex('client').where('id',id).update({
          name:req.body.name
          }).then(function(numberOfUpdatedRows) {
              if(numberOfUpdatedRows) {
                  res.json(success);
                  return;
              }
          }).catch(function(err){
              res.status('500');
              res.json(err);
              return;         
          }); 
  });
  </code></pre>
  
  <p>I solved the problem like this :</p>
  
  <pre><code>knex('client').where('id',id).select('id').then(function(id){
          if(id) {
              //update 
          }else {
              //failed
          }
      }).catch(function(err){
          console.log("select id do not exist");
          res.send("do not exist");
      });
  </code></pre>
  
  <p>For this case also, for invalid ids knex is not calling the catch function but instead of hanging up returns an empty value for the id, which i use for error checking.<br>
  I am a beginner and am sure am there is a better way to doing this.<br>
  Could some one please suggest a better way ?<br>
  Also, I could not find much in the <a href="http://knexjs.org/" rel="nofollow noreferrer">knex documentation</a> about how knex handles error cases like this. So where can I find that information, so I can solve them by myself in the future. Thanks.</p>