<commit_before>/**
 * Implementation of some of Drupal's database layer in Node.js.
 *
 * Ie. stuff that lives in database.inc in Drupal.
 */

var active_db,
    mysql = require('mysql');

/**
 * db_connect() as in Drupal 6.
 *
 * This is much more complex with PDO in Drupal 7, which we won't try to
 * emulate here.
 */
function connect(options, callback) {
  // A shortcut. Currently we only support one active db.
  if (active_db) {
    if (callback) {
      callback(null, active_db);
    }

    return active_db;
  }

  var client = new mysql.Client(options);

  client.connect(function (err) {
    active_db = client;

    if (callback) {
      if (err) {
        callback(err, null);
      }

      callback(null, active_db);
    }
  });
}

/**
 * db_query() as in Drupal (though callback-based).
 *
 * This function assumes that db_connect() has done its work, so be sure
 * to call it and wait for its callback first.
 */
function query(queryString, args, callback) {
  active_db.query(queryString, args, callback);
}

module.exports = {
  active_db: active_db,
  connect: connect,
  query: query
};

<commit_msg>Error message when calling db.query without an active database.<commit_after>/**
 * Implementation of some of Drupal's database layer in Node.js.
 *
 * Ie. stuff that lives in database.inc in Drupal.
 */

var active_db,
    mysql = require('mysql');

/**
 * db_connect() as in Drupal 6.
 *
 * This is much more complex with PDO in Drupal 7, which we won't try to
 * emulate here.
 */
function connect(options, callback) {
  // A shortcut. Currently we only support one active db.
  if (active_db) {
    if (callback) {
      callback(null, active_db);
    }

    return active_db;
  }

  var client = new mysql.Client(options);

  client.connect(function (err) {
    active_db = client;

    if (callback) {
      if (err) {
        callback(err, null);
      }

      callback(null, active_db);
    }
  });
}

/**
 * db_query() as in Drupal (though callback-based).
 *
 * This function assumes that db_connect() has done its work, so be sure
 * to call it and wait for its callback first.
 */
function query(queryString, args, callback) {
  if (!active_db) {
    callback('No active database connection for query.');
  }

  active_db.query(queryString, args, callback);
}

module.exports = {
  active_db: active_db,
  connect: connect,
  query: query
};


{'fraction_non_alphanumeric': 0.11727616645649433, 'fraction_numerical': 0.0016813787305590584, 'mean_word_length': 2.946932006633499, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1710973', 'n_tokens_mistral': 759, 'n_tokens_neox': 745, 'n_words': 258}