<commit_before>const CONFIG = require('config')
const __ = CONFIG.universalPath
const _ = __.require('lib', 'utils')
const dbC = CONFIG.db
const fullUrl = `${dbC.protocol}://${dbC.username}:${dbC.password}@${dbC.host}:${dbC.port}`
const nano = require('nano-blue')(fullUrl)

module.exports = function (dbName) {
  const db = nano.use(dbName)

  return db.info()
    .then((res) => _.success(`${dbName} database: exist`))
    .catch(Create(dbName))
    .then((res) => db)
    .catch(_.ErrorRethrow('db init'))
}

const Create = function (dbName) {
  return function (err) {
    if (err.statusCode === 404) {
      nano.db.create(dbName)
      .then(_.Log(`${dbName} database: created`))
    } else {
      throw err
    }
  }
}
<commit_msg>fixing the lib/db it was returning a promise that was resolving to the db object instead of just returning the db object<commit_after>const CONFIG = require('config')
const __ = CONFIG.universalPath
const _ = __.require('lib', 'utils')
const dbC = CONFIG.db
const fullUrl = `${dbC.protocol}://${dbC.username}:${dbC.password}@${dbC.host}:${dbC.port}`
const nano = require('nano-blue')(fullUrl)

module.exports = function (dbName) {
  const db = nano.use(dbName)
  ensureDbExistance(dbName, db)
  // /!\ we are not returning the ensureDbExistance promise
  // so the database creation might happen after we return
  return db
}

const ensureDbExistance = function (dbName, db) {
  db.info()
  .then((res) => _.success(`${dbName} database: exist`))
  .catch(Create(dbName))
  .catch(_.Error('ensureDbExistance'))
}

const Create = function (dbName) {
  return function (err) {
    if (err.statusCode === 404) {
      nano.db.create(dbName)
      .then(_.Log(`${dbName} database: created`))
    } else {
      throw err
    }
  }
}

{'fraction_non_alphanumeric': 0.166383701188455, 'fraction_numerical': 0.003395585738539898, 'mean_word_length': 3.830601092896175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '3693526', 'n_tokens_mistral': 611, 'n_tokens_neox': 600, 'n_words': 144}