<commit_before>/* jslint node: true */
'use strict';

//
// ## Simple db wrapper

// wrapper for mysql2 lib
// provides select and write functionality and creates a pool
// given a config
//
// * **config** see node-mysql documentation
//
var Db = function (config) {
  this.db = require('mysql2').createPool(config);
};

//
// ## Get connection
//
// Will give you a connection from the pool
//
// * **callback** function with arguments err and connection
//
// Example:
// this._getConnection(function (err, con)) {
//   con.query('SELECT STUFF')
// }
//
Db.prototype._getConnection = function (cb) {
  this.db.getConnection(cb);
};

//
// ## Select
// Accepts prepared statements with ? as placeholder for values
// Data should be an array with values in the same order as corresponding
// ? in the query
//
// result in callback will be an array containing objects, corresponding
// to rows in mysql
// example
// [
//    {field1: "data", field2: "data"},
//    {field1: "data2",field2: "data2"}
// ]
//
// fields contains metadata about the query performed
//
// * **query** Should be a proper select query
// * **data** [] sorted by appearance in query
// * **cb** function (err, result, fields)
//
Db.prototype.select = function select(query, data, cb) {
  this._getConnection(function (err, con) {
    if (err) {
      return cb(err, null);
    }

    con.execute(query, data, function(err, result, fields) {
      cb(err, result, fields);
      con.release();
    });
  });
};

//<commit_msg>feat(main): allow optional data param for select()<commit_after>/* jslint node: true */
'use strict';

//
// ## Simple db wrapper

// wrapper for mysql2 lib
// provides select and write functionality and creates a pool
// given a config
//
// * **config** see node-mysql documentation
//
var Db = function (config) {
  this.db = require('mysql2').createPool(config);
};

//
// ## Get connection
//
// Will give you a connection from the pool
//
// * **callback** function with arguments err and connection
//
// Example:
// this._getConnection(function (err, con)) {
//   con.query('SELECT STUFF')
// }
//
Db.prototype._getConnection = function (cb) {
  this.db.getConnection(cb);
};

//
// ## Select
// Accepts prepared statements with ? as placeholder for values
// Data should be an array with values in the same order as corresponding
// ? in the query
//
// result in callback will be an array containing objects, corresponding
// to rows in mysql
// example
// [
//    {field1: "data", field2: "data"},
//    {field1: "data2",field2: "data2"}
// ]
//
// fields contains metadata about the query performed
//
// * **query** Should be a proper select query
// * **data** [] sorted by appearance in query
// * **cb** function (err, result, fields)
//
Db.prototype.select = function select(query, data, cb) {
  // Allow optional data param
  if (typeof data === 'function') {
    cb = data;
    data = [];
  }

  this._getConnection(function (err, con) {
    if (err) {
      return cb(err, null);
    }

    con.execute(query, data, function(err, result, fields) {
      cb(err, result, fields);
      con.release();
    });
  });
};

//
{'fraction_non_alphanumeric': 0.16364215218083414, 'fraction_numerical': 0.005093919134033747, 'mean_word_length': 2.898263027295285, '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': '992624', 'n_tokens_mistral': 940, 'n_tokens_neox': 934, 'n_words': 329}