<commit_before>var parse = require('./js/parse');
var Datastore = require('nedb');
var db = new Datastore({
  filename: `${__dirname}/tasks.db`,
  autoload: true
});

/**
 * Get a query, parse it and add it to
 * database
 * @param {string} query task query
 */
function addToDB(query) {
  console.log('Enter');
  try {
    var taskObj = parse(query);
    db.insert(taskObj, (err, data) => {
      if(err) {
        console.log(err);
      } else {
        console.log(data);
      }
    });
  } catch (e) {
    console.log(e);
  }
}

angular.module('MainApp')
  .factory('addToDB', () => {
    return addToDB;
  });<commit_msg>Add basic encryption for database<commit_after>var parse = require('./js/parse');
const crypto = require('crypto');
console.log(crypto.createCipher);
var Datastore = require('nedb');
var db = new Datastore({
  filename: `${__dirname}/tasks.db`,
  afterSerialization: (object) => {
    var cipher = crypto.createCipher('aes256', 'sample-key');
    return (cipher.update(object, 'utf8', 'hex') + cipher.final('hex'));
  },
  beforeDeserialization: (object) => {
    var decipher = crypto.createDecipher('aes256', 'sample-key');
    return (decipher.update(object, 'hex', 'utf8') + decipher.final('utf8'));
  },
  autoload: true
});

/**
 * Get a query, parse it and add it to
 * database
 * @param {string} query task query
 */
function addToDB(query) {
  console.log('Enter');
  try {
    var taskObj = parse(query);
    db.insert(taskObj, (err, data) => {
      if(err) {
        console.log(err);
      } else {
        console.log(data);
      }
    });
  } catch (e) {
    console.log(e);
  }
}

angular.module('MainApp')
  .factory('addToDB', () => {
    return addToDB;
  });
{'fraction_non_alphanumeric': 0.18442622950819673, 'fraction_numerical': 0.005269320843091335, 'mean_word_length': 3.1887254901960786, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3066407', 'n_tokens_mistral': 593, 'n_tokens_neox': 586, 'n_words': 130}