<commit_before>'use strict';
var mysql = require('mysql'),
    templates = require('./sql_templates'),
    utils = require('../utils');

module.exports = utils.inherit(Object, {
  defaults: null,
  constructor: function MySQL(options) {
    this.options    = options;
    this.defaults   = {html: '', css: '', javascript: ''};
    this.connection = mysql.createPool(options);
    // note: the this.connection.connect() is implicit
  },
  connect: function (fn) {
    // this used to be conditional to set the charset on the database, but the
    // upgrade in node-mysql meant that we don't need it anymore, so we just
    // keep method for parity with the sqlite adapter.
    fn();
  },
  disconnect: function (fn) {
    this.connection.end(fn);
  },
  getBin: function (params, fn) {
    // This is not the 'id' it's the URL field.
    var values = [params.id, params.revision, params.revision],
        _this = this;

    this.connection.query(templates.getBin, values, function (err, results) {
      if (err) {
        return fn(err);
      }
      if (results.length === 1) {
        results[0].latest = true;
      } else {
        results[0].latest = false;
      }

      fn(null, results[0] && _this.applyBinDefaults(results[0]));
    });
  },
  setBin: function (params, fn) {
    var now = new Date(), values = [
      params.javascript || '',
      params.css || '',
      params.html || '',
      now,
      now,
      params.url,<commit_msg>Fix if there's no bins<commit_after>'use strict';
var mysql = require('mysql'),
    templates = require('./sql_templates'),
    utils = require('../utils');

module.exports = utils.inherit(Object, {
  defaults: null,
  constructor: function MySQL(options) {
    this.options    = options;
    this.defaults   = {html: '', css: '', javascript: ''};
    this.connection = mysql.createPool(options);
    // note: the this.connection.connect() is implicit
  },
  connect: function (fn) {
    // this used to be conditional to set the charset on the database, but the
    // upgrade in node-mysql meant that we don't need it anymore, so we just
    // keep method for parity with the sqlite adapter.
    fn();
  },
  disconnect: function (fn) {
    this.connection.end(fn);
  },
  getBin: function (params, fn) {
    // This is not the 'id' it's the URL field.
    var values = [params.id, params.revision, params.revision],
        _this = this;

    this.connection.query(templates.getBin, values, function (err, results) {
      if (err) {
        return fn(err);
      }
      if (results.length > 1) {
        results[0].latest = false;
      }

      fn(null, results[0] && _this.applyBinDefaults(results[0]));
    });
  },
  setBin: function (params, fn) {
    var now = new Date(), values = [
      params.javascript || '',
      params.css || '',
      params.html || '',
      now,
      now,
      params.url,
{'fraction_non_alphanumeric': 0.14763231197771587, 'fraction_numerical': 0.0031337047353760445, 'mean_word_length': 2.5556930693069306, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '4069163', 'n_tokens_mistral': 883, 'n_tokens_neox': 856, 'n_words': 254}