<commit_before>var _ = require('lodash');
var fs = require('fs');

var util = require('../../core/util.js');
var config = util.getConfig();
var dirs = util.dirs();

var adapter = config.adapters.sqlite;

// verify the correct dependencies are installed
var pluginHelper = require(dirs.core + 'pluginUtil');
var pluginMock = {
  slug: 'sqlite adapter',
  dependencies: config.adapters.sqlite.dependencies
};

var cannotLoad = pluginHelper.cannotLoad(pluginMock);
if(cannotLoad)
  util.die(cannotLoad);

// should be good now
if(config.debug)
  var sqlite3 = require('sqlite3').verbose();
else
  var sqlite3 = require('sqlite3');

var plugins = require(util.dirs().gekko + 'plugins');

var version = adapter.version;

var dbName = config.watch.exchange.toLowerCase() + '_' + version + '.db';
var dir = adapter.dataDirectory;

var fullPath = [dir, dbName].join('/');

var mode = util.gekkoMode();
if(mode === 'realtime') {

  if(!fs.existsSync(dir))
    fs.mkdirSync(dir);


} else if(mode === 'backtest') {

  if(!fs.existsSync(dir))
    util.die('History directory does not exist.');

  if(!fs.existsSync(fullPath))
    util.die(`History database does not exist for exchange ${config.watch.exchange} at version ${version}.`);
}
  

var db = new sqlite3.Database(fullPath);
// enable WAL mode to enable concurrent reads and writes
// http://sqlite.org/wal.html
db.run("PRAGMA journal_mode = WAL")

module.exports = db;<commit_msg>make history dir on import; fix #433<commit_after>var _ = require('lodash');
var fs = require('fs');

var util = require('../../core/util.js');
var config = util.getConfig();
var dirs = util.dirs();

var adapter = config.adapters.sqlite;

// verify the correct dependencies are installed
var pluginHelper = require(dirs.core + 'pluginUtil');
var pluginMock = {
  slug: 'sqlite adapter',
  dependencies: config.adapters.sqlite.dependencies
};

var cannotLoad = pluginHelper.cannotLoad(pluginMock);
if(cannotLoad)
  util.die(cannotLoad);

// should be good now
if(config.debug)
  var sqlite3 = require('sqlite3').verbose();
else
  var sqlite3 = require('sqlite3');

var plugins = require(util.dirs().gekko + 'plugins');

var version = adapter.version;

var dbName = config.watch.exchange.toLowerCase() + '_' + version + '.db';
var dir = adapter.dataDirectory;

var fullPath = [dir, dbName].join('/');

var mode = util.gekkoMode();
if(mode === 'realtime' || mode === 'importer') {

  if(!fs.existsSync(dir))
    fs.mkdirSync(dir);


} else if(mode === 'backtest') {

  if(!fs.existsSync(dir))
    util.die('History directory does not exist.');

  if(!fs.existsSync(fullPath))
    util.die(`History database does not exist for exchange ${config.watch.exchange} at version ${version}.`);
}

var db = new sqlite3.Database(fullPath);
// enable WAL mode to enable concurrent reads and writes
// http://sqlite.org/wal.html
db.run("PRAGMA journal_mode = WAL")

module.exports = db;
{'fraction_non_alphanumeric': 0.16177992411176267, 'fraction_numerical': 0.004484304932735426, 'mean_word_length': 4.492424242424242, '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': '5866962', 'n_tokens_mistral': 960, 'n_tokens_neox': 928, 'n_words': 241}