title: Custom functions for knex
body: <p>There's a number of operations that I do all the time and I was hoping there would be a way to "extend" knex to be able to do them.  </p>
  
  <p>I would like to something like:</p>
  
  <pre><code>oneExists
      result = knex.count(id).from('table').where({'code': 25})
      if (result.length === 0) return false
      if (result.length === 1) return true
      throw an error
  </code></pre>
  
  <p>I would like to be able to do something like </p>
  
  <pre><code>knex.oneExists.count('id').from('table').where({'code': 25}).
  </code></pre>
  
  <p>at the moment i'm writing the code like this:</p>
  
  <pre><code>KnexUtil.oneExists(knex.select('id').from('table').where({code: 25})) 
  </code></pre>
  
  <p>which returns a promise</p>
  
  <p>I've looked through the knex codebase and i'm not sure:</p>
  
  <ol>
  <li>how to chain this (and whether i would do this in /lib/query/compiler.js)</li>
  <li>how to just make an extension to knex so i don't need to modify the original codebase</li>
  </ol>