title: Knexjs If not exist insert else update
body: <p>How can this code be optimized?
  I don't want to call where 2 times... Is it possible to have better query than this?</p>
  
  <pre><code>    return self.db.clientDevices.where(device).then(function (rows) {
          if (rows.length != 1) {
              device.key = value;
              self.db.clientDevices.insert(device).then();
          } else {
              self.db.clientDevices.where(device).update(device).then();
          }
      });
  </code></pre>