title: How to promisify your own javascript api which uses another promisified api with Bluebird?
body: <p>I'm struggling with this a bit. I want to build an abstraction layer over a database driver module in node. I've already promisified the driver module by doing the following:</p>
  
  <pre><code>var sql = Promise.promisifyAll(require('sql-driver'));
  </code></pre>
  
  <p>Then within my own js file I want to wrap queries like so:</p>
  
  <pre><code>function query(queryString, transaction) {
     sql.connectAsync(config).then(function() {
  
        var req = new sql.Request(transaction);
        req.queryAsync(queryString).then(function(resultSet)) {
            console.log(resultSet);
        });
     });
  }
  </code></pre>
  
  <p>How can I promisify (using bluebird) so that my query function is also promisified and returns a promise or thenable?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I want my wrapper method to also be promisified so that the user can do something like this:</p>
  
  <pre><code>var myDbWrapper = require('my-db-wapper');
  function getData() {
      myDbWrapper.startTransaction()
      .then(function(transaction) {
          return myDbWrapper.query('select 1 as number', transaction);
       })
      .then(function(resultSet) {
          console.log(resultSet);
       }).
      .catch(function(e) {
          console.error(e);
      });
  }
  </code></pre>
  
  <p>I'm sure this isn't working code, just trying to convey the idea. Also, this example only shows one query and doesn't show the commit method, which is also part of the wrapper. Can someone show me an example use promises to do a whole transaction with more than one query and then a 'commit' if no errors? </p>
  
  <p><strong>Update 2:</strong></p>
  
  <p>idbehold's example below won't allow me to do this type of thing assuming that we don't care about a transaction at this time, just a simple query:</p>
  
  <pre><code>myDbWrapper.query(queryString, undefined)
  .then(function(recordSet) {
     console.log(recordSet);
  })
  .catch(function(err) {
     console.error(err);
  });
  </code></pre>
  
  <p>How can I enable my query method to work that way?</p>
  
  <p><strong>Update 3:</strong></p>
  
  <p>I've found my answer. See below.</p>