2016-06-18 21:53:18 +02:00
|
|
|
'use strict';
|
2016-10-26 10:43:11 +02:00
|
|
|
|
2016-12-27 21:03:50 +01:00
|
|
|
const knex = require('knex');
|
2014-10-21 15:28:10 +02:00
|
|
|
|
2017-06-28 10:17:14 +02:00
|
|
|
module.exports.createDb = function({
|
2020-04-13 22:38:46 +02:00
|
|
|
db,
|
2017-06-28 10:17:14 +02:00
|
|
|
poolMin = 2,
|
|
|
|
poolMax = 20,
|
2020-04-13 22:38:46 +02:00
|
|
|
databaseSchema,
|
|
|
|
getLogger,
|
2017-06-28 10:17:14 +02:00
|
|
|
}) {
|
2020-04-13 22:38:46 +02:00
|
|
|
const logger = getLogger('db-pool.js');
|
|
|
|
return knex({
|
2014-11-14 15:06:53 +01:00
|
|
|
client: 'pg',
|
2020-11-20 11:37:56 +01:00
|
|
|
version: db.version,
|
2020-04-13 22:38:46 +02:00
|
|
|
connection: db,
|
2016-11-13 15:15:33 +01:00
|
|
|
pool: { min: poolMin, max: poolMax },
|
|
|
|
searchPath: databaseSchema,
|
2020-04-13 22:38:46 +02:00
|
|
|
log: {
|
|
|
|
debug: msg => logger.debug(msg),
|
|
|
|
info: msg => logger.info(msg),
|
|
|
|
warn: msg => logger.warn(msg),
|
|
|
|
error: msg => logger.error(msg),
|
|
|
|
},
|
2014-11-14 15:06:53 +01:00
|
|
|
});
|
2016-05-01 22:53:09 +02:00
|
|
|
};
|