<commit_before>"use strict";
//var mysql = require('mysql');
var dbProperties = require('../config/config.json');
//var x = dbProperties.database.client
//var y = x.toString().toLowerCase();
//console.log('y:', y);
var knex = require('knex')({
    client: dbProperties.database.client.toLowerCase(),
    connection: {
        host: dbProperties.database[dbProperties.database.client].host,
        port: dbProperties.database[dbProperties.database.client].port,
        user: dbProperties.database[dbProperties.database.client].user,
        password: dbProperties.database[dbProperties.database.client].password,
        database: dbProperties.database[dbProperties.database.client].database,
        debug: dbProperties.database[dbProperties.database.client].debug
    }
});
console.log(knex);

function closeDb(){
    knex.destroy();
}
function mysqlCallback(promise, error, results, fields){
    if (error) {
        console.log('========MYSQL ERR:', error);
        if (error.errno == 1045) {
            console.log("YOU FUCKED UP. Check the db connection settings. Check user existence."
                        + "\nCheck db existence. Check table. Call The Lone Ranger, <NAME>, Robocop.");
        }
         promise.resolve();
         return 'error';
        //ECONNREFUSED is mysql running?
        //1064 ER_PARSE_ERROR woops. my bad, dawg.
     }
    if (results) {
        console.log('========RESULTS:', results);
    }
    if (fields) {
        console.log('\n========FIELDS:', fields);
    }
    console.log('nah im here');
//    promise.resolve;
                    //{        then: function(onFulfill, onReject) { onFulfill("fulfilled!"); }    });
    return promise;
}


function mysqlConnection(){
    var connection = mysql.createConnection({
      "host": dbProperties.database.mysql.host,
      "port": dbProperties.database.mysql.port,
      "user": dbProperties.database.mysql.user,
      "password": dbProperties.database.mysql.password,
      "database": dbProperties.database.mysql.database,
      "debug": dbProperties.database.mysql.debug
    });
    //console.log('dbProperties.blahblah', dbProperties.database.mysql);
    connection.on('error', function(err) {
      console.log('ERROR! HUZZAH!!!', err.code); // #TODO: do something with this
    });
    /*connection.connect(function(err) {
      if (err) {
        console.log('error connecting: ' + err.stack);
        return;
      }
      console.log('connected as id ' + connection.threadId);
    });
    
    if (connection.threadId === null) {
        console.error('NOT CONNECTED TO DATABASE!');
        return 'error';
    }
//console.log('mysqlConnection success');
    */
return connection;
}


function createAddressTable(){

    knex.schema.createTableIfNotExists('coin_index', function (table) {
        table.increments();
        table.integer('timestamp');
        table.string('crypto_symbol');
        table.string('crypto_address');
        table.string('external_address');
    }).catch(function(error){
        console.log('error in knex table creation');
        })
    .return;
/*    var queryCreateTable = 'CREATE TABLE IF NOT EXISTS coin_index (id INT AUTO_INCREMENT PRIMARY KEY, timestamp INT, crypto_symbol VARCHAR(255), crypto_address VARCHAR(255), external_address VARCHAR(255));';
    var db = mysqlConnection();
    db.query(queryCreateTable, mysqlCallback);//error, results, fields));
    return;
*/
}


var recordNewAddressRelationship = function( cryptoAddress, cryptoSymbol, externalAccount, timestamp, callback){
    var post =  {"timestamp": timestamp, "crypto_symbol": cryptoSymbol, "crypto_address": cryptoAddress, "external_address": externalAccount};
  //  var db = mysqlConnection();<commit_msg>fix hanging promise on createTable<commit_after>"use strict";
//var mysql = require('mysql');
var dbProperties = require('../config/config.json');
//var x = dbProperties.database.client
//var y = x.toString().toLowerCase();
//console.log('y:', y);
var knex = require('knex')({
    client: dbProperties.database.client.toLowerCase(),
    connection: {
        host: dbProperties.database[dbProperties.database.client].host,
        port: dbProperties.database[dbProperties.database.client].port,
        user: dbProperties.database[dbProperties.database.client].user,
        password: dbProperties.database[dbProperties.database.client].password,
        database: dbProperties.database[dbProperties.database.client].database,
        debug: dbProperties.database[dbProperties.database.client].debug
    }
});
console.log(knex);

function closeDb(){
    knex.destroy();
}
function mysqlCallback(promise, error, results, fields){
    if (error) {
        console.log('========MYSQL ERR:', error);
        if (error.errno == 1045) {
            console.log("YOU FUCKED UP. Check the db connection settings. Check user existence."
                        + "\nCheck db existence. Check table. Call The Lone Ranger, <NAME>, Robocop.");
        }
         promise.resolve();
         return 'error';
        //ECONNREFUSED is mysql running?
        //1064 ER_PARSE_ERROR woops. my bad, dawg.
     }
    if (results) {
        console.log('========RESULTS:', results);
    }
    if (fields) {
        console.log('\n========FIELDS:', fields);
    }
    console.log('nah im here');
//    promise.resolve;
                    //{        then: function(onFulfill, onReject) { onFulfill("fulfilled!"); }    });
    return promise;
}


function mysqlConnection(){
    var connection = mysql.createConnection({
      "host": dbProperties.database.mysql.host,
      "port": dbProperties.database.mysql.port,
      "user": dbProperties.database.mysql.user,
      "password": dbProperties.database.mysql.password,
      "database": dbProperties.database.mysql.database,
      "debug": dbProperties.database.mysql.debug
    });
    //console.log('dbProperties.blahblah', dbProperties.database.mysql);
    connection.on('error', function(err) {
      console.log('ERROR! HUZZAH!!!', err.code); // #TODO: do something with this
    });
    /*connection.connect(function(err) {
      if (err) {
        console.log('error connecting: ' + err.stack);
        return;
      }
      console.log('connected as id ' + connection.threadId);
    });
    
    if (connection.threadId === null) {
        console.error('NOT CONNECTED TO DATABASE!');
        return 'error';
    }
//console.log('mysqlConnection success');
    */
return connection;
}


function createAddressTable(){

    knex.schema.createTableIfNotExists('coin_index', function (table) {
        table.increments();
        table.integer('timestamp');
        table.string('crypto_symbol');
        table.string('crypto_address');
        table.string('external_address');
    }).catch(function(error){
        console.log('error in knex table creation');
        })
    .then(function(result){
        console.log('creationResult:', result);
        //return true;
        closeDb();});/*
/*    var queryCreateTable = 'CREATE TABLE IF NOT EXISTS coin_index (id INT AUTO_INCREMENT PRIMARY KEY, timestamp INT, crypto_symbol VARCHAR(255), crypto_address VARCHAR(255), external_address VARCHAR(255));';
    var db = mysqlConnection();
    db.query(queryCreateTable, mysqlCallback);//error, results, fields));
    return;
*/
}


var recordNewAddressRelationship = function( cryptoAddress, cryptoSymbol, externalAccount, timestamp, callback){
    var post =  {"timestamp": timestamp, "crypto_symbol": cryptoSymbol, "crypto_address": cryptoAddress, "external_address": externalAccount};
  //  var db = mysqlConnection();
{'fraction_non_alphanumeric': 0.14781575821565263, 'fraction_numerical': 0.004487264088689455, 'mean_word_length': 3.191371681415929, 'pattern_counts': {'":': 20, '<': 5, '<?xml version=': 0, '>': 5, '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': '3782181', 'n_tokens_mistral': 2150, 'n_tokens_neox': 2104, 'n_words': 456}