index.js
function _attachBatchMethod(qb) {
  /**
   *
   * @param options
   * @param cassakni
   * @param cb
   * @returns {Client|exports|module.exports}
   */
  qb.batch = function (options, cassakni, cb) {

    var _options
      , _cassakni
      , _cb;

    // options is really cassakni, cassakni is cb
    if (_.isArray(options)) {
      _options = {};
      _cassakni = options;
      _cb = cassakni;
    }
    // standard order
    else {
      _options = options;
      _cassakni = cassakni;
      _cb = cb;
    }

    if (!_.isFunction(_cb)) {
      _cb = _.noop;
    }

    if (cassandra !== null && cassandra.connected) {

      var error = null
        , statements = _.map(_cassakni, function (qb) {

          if (!qb.toString || qb.toString() !== duckType) {
            error = new Error("Invalid input to CassanKnex#batch.");
            return {};
          }
          else {
            return {query: qb.cql(), params: qb.bindings()};
          }
        });

      if (error) {
        return _cb(error);
      }

      cassandra.batch(statements, _options, _cb);
    }
    else {
      _cb(new Error("Cassandra client is not initialized."));
    }

    // maintain chain
    return qb;
  };
}
function _attachBatchMethod(qb) {
  /**
   *
   * @param options
   * @param cassakni
   * @param cb
   * @returns {Client|exports|module.exports}
   */
  qb.batch = function (options, cassakni, cb) {

    var _options
      , _cassakni
      , _cb;

    // options is really cassakni, cassakni is cb
    if (_.isArray(options)) {
      _options = {};
      _cassakni = options;
      _cb = cassakni;
    }
    // standard order
    else {
      _options = options;
      _cassakni = cassakni;
      _cb = cb;
    }

    if (!_.isFunction(_cb)) {
      _cb = _.noop;
    }

    if (cassandra !== null && cassandra.connected) {

      var error = null
        , statements = _.map(_cassakni, function (qb) {

          if (!qb.toString || qb.toString() !== duckType) {
            error = new Error("Invalid input to CassanKnex#batch.");
            return {};
          }
          else {
            return {query: qb.cql(), params: qb.bindings()};
          }
        });

      if (error) {
        return _cb(error);
      }

      cassandra.batch(statements, _options, _cb);
    }
    else {
      _cb(new Error("Cassandra client is not initialized."));
    }

    // maintain chain
    return qb;
  };
}
function _attachBatchMethod ( qb ) { /**
   *
   * @param options
   * @param cassakni
   * @param cb
   * @returns {Client|exports|module.exports}
   */ qb . batch = function ( options , cassakni , cb ) { var _options , _cassakni , _cb ; // options is really cassakni, cassakni is cb if ( _ . isArray ( options ) ) { _options = { } ; _cassakni = options ; _cb = cassakni ; } // standard order else { _options = options ; _cassakni = cassakni ; _cb = cb ; } if ( ! _ . isFunction ( _cb ) ) { _cb = _ . noop ; } if ( cassandra !== null && cassandra . connected ) { var error = null , statements = _ . map ( _cassakni , function ( qb ) { if ( ! qb . toString || qb . toString ( ) !== duckType ) { error = new Error ( "Invalid input to CassanKnex#batch." ) ; return { } ; } else { return { query : qb . cql ( ) , params : qb . bindings ( ) } ; } } ) ; if ( error ) { return _cb ( error ) ; } cassandra . batch ( statements , _options , _cb ) ; } else { _cb ( new Error ( "Cassandra client is not initialized." ) ) ; } // maintain chain return qb ; } ; }
hooks the 'batch' cassandra client method to our query builder object
@param qb
@private
hooks the batch cassandra client method to our query builder object