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.
Currently
assessmentsDb.js
andcohorts.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
):Then update the files mentioned above to use this new module.