harakeke-2019 / EDAMAME

EDAMAME: Enspiral Dev Academy Management of Assessment Modules Emily
1 stars 3 forks source link

Extract db config into separate module #33

Closed bryceknz closed 5 years ago

bryceknz commented 5 years ago

Currently assessmentsDb.js and cohorts.js contains several lines of code for pulling in the database configuration. If each new set of database functions is designed in this way, we will have unnecessarily duplicated code.

My preference would be to have the following lines extracted into a new file (db/index.js):

const environment = process.env.NODE_ENV || 'development'
const config = require('../../knexfile')[environment]  // Check this filepath is correct before committing!
const connection = require('knex')(config)

module.exports = connection

Then update the files mentioned above to use this new module.