<commit_before>"use strict";
var mongodb = require('mongodb');
var MongoClient = mongodb.MongoClient;
var Q = require('q');

var _ready = false;
var _db = null;
var db = module.exports = {
   SPRITES: "spriteSubmissions",
   USERS: "users",
   routes:function(server){
      MongoClient.connect(process.env.MONGOHQ_URL || require("../.env.json").MONGOHQ_URL, {}, function(err, db) {
         _db = db;
      });
   },

   instance: function(){
      if(!_db){
         throw new Error("DB not connected.  Connection is established when routes(expressServer) is called.");
      }
      return _db;
   },

   users: function(){
      var inst = db.instance();
      return inst.collection(db.USERS);
   },

   sprites: function(){
      var inst = db.instance();
      return inst.collection(db.SPRITES);
   },<commit_msg>Don't blow up with mongo connection problems.<commit_after>"use strict";
var mongodb = require('mongodb');
var MongoClient = mongodb.MongoClient;
var Q = require('q');

var _ready = false;
var _error = null;
var _db = null;
var db = module.exports = {
   SPRITES: "spriteSubmissions",
   USERS: "users",
   routes:function(server){
      MongoClient.connect(process.env.MONGOHQ_URL || require("../.env.json").MONGOHQ_URL, {}, function(err, db) {
         _error = err;
         _db = db;
      });
   },

   instance: function(){
      if(_error){
         throw new Error("Failed to connect to DB");
      }
      if(!_db){
         throw new Error("DB not connected.  Connection is established when routes(expressServer) is called.");
      }
      return _db;
   },

   users: function(){
      var inst = db.instance();
      return inst.collection(db.USERS);
   },

   sprites: function(){
      var inst = db.instance();
      return inst.collection(db.SPRITES);
   },
{'fraction_non_alphanumeric': 0.14763231197771587, 'fraction_numerical': 0.0, 'mean_word_length': 2.8376068376068377, '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': '5749136', 'n_tokens_mistral': 587, 'n_tokens_neox': 565, 'n_words': 143}