2014-10-21 15:28:10 +02:00
|
|
|
var anyDB = require('any-db'),
|
|
|
|
logger = require('./logger'),
|
|
|
|
nconf = require('nconf'),
|
|
|
|
fs = require('fs'),
|
|
|
|
ini = require('ini');
|
|
|
|
|
|
|
|
|
|
|
|
function createDbPool() {
|
2014-10-23 10:05:56 +02:00
|
|
|
if (process.env.DATABASE_URL) {
|
|
|
|
logger.info('unleash started with DATABASE_URL');
|
|
|
|
return anyDB.createPool(process.env.DATABASE_URL);
|
2014-10-23 14:39:50 +02:00
|
|
|
} else if (nconf.argv().get('databaseini') !== undefined) {
|
|
|
|
// Finn specific way of delivering env variables
|
2014-10-23 10:05:56 +02:00
|
|
|
var databaseini = nconf.argv().get('databaseini');
|
2014-10-21 15:28:10 +02:00
|
|
|
logger.info('unleash started with databaseini: ' + databaseini);
|
|
|
|
var config = ini.parse(fs.readFileSync(databaseini, 'utf-8'));
|
|
|
|
return anyDB.createPool(config.DATABASE_URL, {min: 2, max: 20});
|
|
|
|
}
|
2014-10-23 14:39:50 +02:00
|
|
|
|
|
|
|
throw new Error('please set DATABASE_URL or pass --databaseini');
|
2014-10-21 15:28:10 +02:00
|
|
|
}
|
|
|
|
|
2014-10-23 10:05:56 +02:00
|
|
|
module.exports = createDbPool();
|