<commit_before>const credentials = require('../../mysqlCred.json')
const config = require('../../config.json')
const sqlType = config.feedManagement.sqlType.toLowerCase()
const sql = (sqlType === 'mysql') ? require('mysql') : require('sqlite3').verbose()


module.exports = function(callback) {
  if (sqlType === 'mysql') {
  let con, attempts = 0;
  // let con;

    (function connect(finalErr) {
      if (attempts === 9 && finalErr) throw new Error(`Could not connect to database after 10 attempts, terminating. (${finalErr})`);
      con = sql.createConnection(credentials); //MySQL connections will automatically close unless new connections are made

      con.connect(function(err) {
        if (err) {
          console.log(`Error connecting to database ${config.feedManagement.databaseName} (${err}). Attempting to reconnect.`);
          attempts++;
          return setTimeout(connect, 2000, err);
          // return callback(err);
        }

        con.query(`create database if not exists \`${config.feedManagement.databaseName}\``, function(err) {
          if (err) throw err;
        })
        con.query(`use ${config.feedManagement.databaseName}`, function(err) {
          if (err) throw err;
        })
        con.query(`set collation_connection = 'utf8_general_ci'`, function(err) {
          if (err) throw err;
        })
        callback();
      });

      con.on('error', function(err) {
        if (err.code === 'PROTOCOL_CONNECTION_LOST') {
          connect(err);
          attempts++;
        }
        else throw err;
      });
    })()
    return con;
  }

  // So much simpler!
  else if (sqlType == "sqlite3") {
    return new sql.Database(`./${config.feedManagement.databaseName}.db`, callback);
  }<commit_msg>Added backticks to use database, fixes #14<commit_after>const credentials = require('../../mysqlCred.json')
const config = require('../../config.json')
const sqlType = config.feedManagement.sqlType.toLowerCase()
const sql = (sqlType === 'mysql') ? require('mysql') : require('sqlite3').verbose()


module.exports = function(callback) {
  if (sqlType === 'mysql') {
  let con, attempts = 0;
  // let con;

    (function connect(finalErr) {
      if (attempts === 9 && finalErr) throw new Error(`Could not connect to database after 10 attempts, terminating. (${finalErr})`);
      con = sql.createConnection(credentials); //MySQL connections will automatically close unless new connections are made

      con.connect(function(err) {
        if (err) {
          console.log(`Error connecting to database ${config.feedManagement.databaseName} (${err}). Attempting to reconnect.`);
          attempts++;
          return setTimeout(connect, 2000, err);
          // return callback(err);
        }

        con.query(`create database if not exists \`${config.feedManagement.databaseName}\``, function(err) {
          if (err) throw err;
        })
        con.query(`use \`${config.feedManagement.databaseName}\``, function(err) {
          if (err) throw err;
        })
        con.query(`set collation_connection = 'utf8_general_ci'`, function(err) {
          if (err) throw err;
        })
        callback();
      });

      con.on('error', function(err) {
        if (err.code === 'PROTOCOL_CONNECTION_LOST') {
          connect(err);
          attempts++;
        }
        else throw err;
      });
    })()
    return con;
  }

  // So much simpler!
  else if (sqlType == "sqlite3") {
    return new sql.Database(`./${config.feedManagement.databaseName}.db`, callback);
  }
{'fraction_non_alphanumeric': 0.15179835740583403, 'fraction_numerical': 0.006796941376380629, 'mean_word_length': 2.6830031282586027, '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': '6136112', 'n_tokens_mistral': 1010, 'n_tokens_neox': 988, 'n_words': 256}