<commit_before>mongoose = require 'mongoose'
fs = require 'fs'

# DB Models
models = require './models'

# Gets a connection to MongoLab or a local MongoDB instance
connect = ->
  CURRENT_ENV = process.env.ENV or 'local'
  envContext = JSON.parse(fs.readFileSync("./.environment/#{CURRENT_ENV}"))

  console.log "[DB] ENVIRONMENT: #{CURRENT_ENV}"
  console.log "[DB] connecting as user: #{envContext.user}"
  console.log "[DB] database URL: #{envContext.url}"
  connection = mongoose.createConnection(
    "#{envContext.user}:#{envContext.password}@#{envContext.url}",
    {
      journal: true
      # database: envContext.database or 'voting'
    }
  )
  connection.on('connected', handleDbConnected)
  connection.on('disconnected', handleDbDisconnected)
  connection

handleDbConnected = ->
  console.log("[DB] database connected")

handleDbDisconnected = ->
  console.log("[DB] database disconnected")

module.exports = {connect, models}<commit_msg>Added keepAlive todo<commit_after>mongoose = require 'mongoose'
fs = require 'fs'

# DB Models
models = require './models'

# Gets a connection to MongoLab or a local MongoDB instance
connect = ->
  CURRENT_ENV = process.env.ENV or 'local'
  envContext = JSON.parse(fs.readFileSync("./.environment/#{CURRENT_ENV}"))

  console.log "[DB] ENVIRONMENT: #{CURRENT_ENV}"
  console.log "[DB] connecting as user: #{envContext.user}"
  console.log "[DB] database URL: #{envContext.url}"
  connection = mongoose.createConnection(
    "#{envContext.user}:#{envContext.password}@#{envContext.url}",
    {
      journal: true
      # database: envContext.database or 'voting'
    }
  )
  connection.on('connected', handleDbConnected)
  connection.on('disconnected', handleDbDisconnected)
  connection

handleDbConnected = ->
  console.log("[DB] database connected")

handleDbDisconnected = ->
  console.log("[DB] database disconnected")
  # TODO: worry about using keepAlive and how to reconnect on error

module.exports = {connect, models}
{'fraction_non_alphanumeric': 0.13730439172135286, 'fraction_numerical': 0.0, 'mean_word_length': 4.614730878186969, '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': '5574523', 'n_tokens_mistral': 613, 'n_tokens_neox': 611, 'n_words': 148}