var mongojs = require('mongojs')
	, Datastore = require('nedb')
	, statsModel = require('../models/stats')
	, db;

function dbCursor(cursor, callback) {
	if (process.env.DB_URL) {
		cursor.toArray(callback);
	} else {
		cursor.exec(callback);
	}
}

function runDatabase() {
	dbCursor(db.find().sort({ _id: -1 }).limit(1), function(err, docs) {
		console.log(docs);
		if (docs.length <= 0) {
			// No docs exists, insert the stats model
			db.insert(statsModel);
		}
		require('./daemon').run();
	});
}

exports.loadDatabase = function(callback) {
	if (process.env.DB_URL) {
		exports.db = db = mongojs(process.env.DB_URL, ['mrma']).mrma;
	} else {
		exports.db = db = new Datastore({ filename: process.cwd() + '/datastore/data', autoload: true });
	}
	runDatabase();
}
@@ -99,16 +99,68 @@
 /stats')
+.stats%0A%09, solsModel = require('../models/sols').sols
 %0A%09, db;%0A
@@ -393,29 +393,8 @@
 ) %7B%0A
-%09%09console.log(docs);%0A
 %09%09if
@@ -452,19 +452,19 @@
 the 
-stats
+base
  model
+s
 %0A%09%09%09
@@ -473,16 +473,20 @@
 .insert(
+new 
 statsMod
@@ -487,16 +487,49 @@
 atsModel
+());%0A%09%09%09db.insert(new solsModel()
 );%0A%09%09%7D%0A%09

insert models