<commit_before>var uuid 		= require('node-uuid');
var crypto 		= require('crypto');
var mysql      = require('mysql');
var connection = mysql.createConnection({
	host     : process.env.OPENSHIFT_MYSQL_DB_HOST,
	user     : process.env.OPENSHIFT_MYSQL_DB_USERNAME,
	password : <PASSWORD>.OPEN<PASSWORD>,
	port     : process.env.OPENSHIFT_MYSQL_DB_PORT,
	database : process.env.OPENSHIFT_APP_NAME
}); 

connection.connect(function(err) {
	if (err) {
		console.error('error connecting: ' + err.stack);
		throw err;
		return;
	}
	console.log('connected as id ' + connection.threadId);
});

var dbConfig 	= {
	algorithm 	: 'aes-256-ctr',
	password  	: <PASSWORD>	
};
  
function encrypt(text){
  var cipher = crypto.createCipher(dbConfig.algorithm,dbConfig.password)
  var crypted = cipher.update(text,'utf8','hex')
  crypted += cipher.final('hex');
  return crypted;
}
 
function decrypt(text){
  var decipher = crypto.createDecipher(dbConfig.algorithm,dbConfig.password)
  var dec = decipher.update(text,'hex','utf8')
  dec += decipher.final('utf8');
  return dec;
}  
 
connection.query(
	"CREATE TABLE IF NOT EXISTS `UserData` (" + 
	"  `ID` int(11) NOT NULL AUTO_INCREMENT," + 
	"  `key` varchar(50) NOT NULL," + 
	"  `value` text NOT NULL," + 
	"  `expire` datetime NOT NULL," + 
	"  PRIMARY KEY (`ID`)" + 
	") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"
);
	
// Clear expired data
connection.query("DELETE FROM UserData WHERE expire < ?" , [Math.round(new Date().getTime() / 1000)]);


module.exports = {
	CreateUser: function() {
		var id = uuid.v1();
		console.log("Creating User " + id);		
		var data  = {
			key		: id,
			value	: encrypt('{}'),
			expire	: Math.round(new Date().getTime() / 1000)
		};
		
		var query = connection.query('INSERT INTO UserData SET ?', data, function(err, result) {});
		return id;
	},
	DeleteUser: function (key, value) {
		console.log("Delete User " + key);
		var sql = "DELETE FROM UserData WHERE key = " + connection.escape(key);
		connection.query(sql, function (err, result) {
			if (err) throw err;
			console.log('Delete Expired data: Count ' + result.affectedRows + ' rows');
		});		
	},
	UpdateUser: function (key, value) {
		console.log("Update User")
				
		var sql = "UPDATE UserData SET value = "+ connection.escape(encrypt(JSON.stringify(value))) +
				", expire = " + connection.escape((Math.round(new Date().getTime() / 1000) + global.setting.DataStoreTimeout))  + 
				" WHERE key = " + connection.escape(key);
	
		connection.query(sql , function (err, result) {
			if (err) throw err;
			console.log('changed ' + result.changedRows + ' rows');
		});
	},
	GetUser: function (key, callback) {
		// Update expire date
		
		var sql = "UPDATE UserData SET expire = " + connection.escape((Math.round(new Date().getTime() / 1000) + global.setting.DataStoreTimeout)) + 
			" WHERE key = " + connection.escape(key);
		
		connection.query(sql, function (err, result) {
			if (err) throw err;
			console.log('changed ' + result.changedRows + ' rows');
		});
		
		var sql    = "SELECT value FROM UserData WHERE key = " +  connection.escape(key);
		connection.query(sql, function(err, row) {
			if (typeof row != 'undefined') {
				return callback(JSON.parse(decrypt(row.value)));
			}
			return callback(null);
		});
	} 
};<commit_msg>Minor<commit_after>var uuid 		= require('node-uuid');
var crypto 		= require('crypto');
var mysql      = require('mysql');
var connection = mysql.createConnection({
	host     : process.env.OPENSHIFT_MYSQL_DB_HOST,
	user     : process.env.OPENSHIFT_MYSQL_DB_USERNAME,
	password : <PASSWORD>,
	port     : process.env.OPENSHIFT_MYSQL_DB_PORT,
	database : process.env.OPENSHIFT_APP_NAME
}); 

connection.connect(function(err) {
	if (err) {
		console.error('error connecting: ' + err.stack);
		throw err;
		return;
	}
	console.log('connected as id ' + connection.threadId);
});

var dbConfig 	= {
	algorithm 	: 'aes-256-ctr',
	password  	: <PASSWORD>.NEON_SECURE_PASSWORD	
};
  
function encrypt(text){
  var cipher = crypto.createCipher(dbConfig.algorithm,dbConfig.password)
  var crypted = cipher.update(text,'utf8','hex')
  crypted += cipher.final('hex');
  return crypted;
}
 
function decrypt(text){
  var decipher = crypto.createDecipher(dbConfig.algorithm,dbConfig.password)
  var dec = decipher.update(text,'hex','utf8')
  dec += decipher.final('utf8');
  return dec;
}  
 
connection.query(
	"CREATE TABLE IF NOT EXISTS `UserData` (" + 
	"  `ID` int(11) NOT NULL AUTO_INCREMENT," + 
	"  `key` varchar(50) NOT NULL," + 
	"  `value` text NOT NULL," + 
	"  `expire` datetime NOT NULL," + 
	"  PRIMARY KEY (`ID`)" + 
	") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"
);
	
// Clear expired data
connection.query("DELETE FROM UserData WHERE expire < ?" , [Math.round(new Date().getTime() / 1000)]);


module.exports = {
	CreateUser: function() {
		var id = uuid.v1();
		console.log("Creating User " + id);		
		var data  = {
			key		: id,
			value	: encrypt('{}'),
			expire	: Math.round(new Date().getTime() / 1000)
		};
		
		var query = connection.query('INSERT INTO UserData SET ?', data, function(err, result) {});
		return id;
	},
	DeleteUser: function (key, value) {
		console.log("Delete User " + key);
		var sql = "DELETE FROM UserData WHERE key = " + connection.escape(key);
		connection.query(sql, function (err, result) {
			if (err) throw err;
			console.log('Delete Expired data: Count ' + result.affectedRows + ' rows');
		});		
	},
	UpdateUser: function (key, value) {
		console.log("Update User")
				
		var sql = "UPDATE UserData SET value = "+ connection.escape(encrypt(JSON.stringify(value))) +
				", expire = " + connection.escape((Math.round(new Date().getTime() / 1000) + global.setting.DataStoreTimeout))  + 
				" WHERE key = " + connection.escape(key) + ";";
		console.log(sql);
	
		connection.query(sql, function (err, result) {
			if (err) throw err;
			console.log('changed ' + result.changedRows + ' rows');
		});
	},
	GetUser: function (key, callback) {
		// Update expire date
		
		var sql = "UPDATE UserData SET expire = " + connection.escape((Math.round(new Date().getTime() / 1000) + global.setting.DataStoreTimeout)) + 
			" WHERE key = " + connection.escape(key)  + ";";
		console.log(sql);
		
		connection.query(sql, function (err, result) {
			if (err) throw err;
			console.log('changed ' + result.changedRows + ' rows');
		});
		
		var sql    = "SELECT value FROM UserData WHERE key = " +  connection.escape(key);
		connection.query(sql, function(err, row) {
			if (typeof row != 'undefined') {
				return callback(JSON.parse(decrypt(row.value)));
			}
			return callback(null);
		});
	} 
};
{'fraction_non_alphanumeric': 0.15997585270147902, 'fraction_numerical': 0.008753395713854513, 'mean_word_length': 3.784837545126354, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, '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': '5742040', 'n_tokens_mistral': 2468, 'n_tokens_neox': 2211, 'n_words': 500}