parent
055ed3e86d
commit
6cfae4ebe5
4 changed files with 27 additions and 25 deletions
@ -0,0 +1,24 @@ |
|||||||
|
const environment = process.env.ENVIRONMENT || 'development' |
||||||
|
import config from '../knexfile'; |
||||||
|
import Knex from 'knex'; |
||||||
|
|
||||||
|
export default function get_knex() { |
||||||
|
if (!Object.keys(config).includes(environment)) { |
||||||
|
throw "No Knex database configuration was found for environment '" + |
||||||
|
environment + "'. Please check your configuration."; |
||||||
|
} |
||||||
|
|
||||||
|
var _knex = undefined; |
||||||
|
console.log("Using Knex config: ", config[environment]) |
||||||
|
|
||||||
|
try { |
||||||
|
_knex = require('knex')(config[environment]); |
||||||
|
} catch (e) { |
||||||
|
throw [ |
||||||
|
"Failed to initialize Knex database connection with config: " |
||||||
|
+ JSON.stringify(config[environment]), |
||||||
|
e |
||||||
|
]; |
||||||
|
} |
||||||
|
return _knex; |
||||||
|
} |
@ -1,23 +0,0 @@ |
|||||||
const environment = process.env.ENVIRONMENT || 'development' |
|
||||||
import config from '../knexfile'; |
|
||||||
import Knex from 'knex'; |
|
||||||
|
|
||||||
if (!Object.keys(config).includes(environment)) { |
|
||||||
throw "No Knex database configuration was found for environment '" + |
|
||||||
environment + "'. Please check your configuration."; |
|
||||||
} |
|
||||||
|
|
||||||
var _knex = undefined; |
|
||||||
|
|
||||||
try { |
|
||||||
_knex = require('knex')(config[environment]); |
|
||||||
} catch (e) { |
|
||||||
throw [ |
|
||||||
"Failed to initialize Knex database connection with config: " |
|
||||||
+ JSON.stringify(config[environment]), |
|
||||||
e |
|
||||||
]; |
|
||||||
} |
|
||||||
|
|
||||||
const knex:Knex = _knex; |
|
||||||
export default knex; |
|
Loading…
Reference in new issue