2021-06-17 20:33:34 +02:00
|
|
|
import { knex, Knex } from 'knex';
|
2021-04-22 10:07:10 +02:00
|
|
|
import { IUnleashConfig } from '../types/option';
|
|
|
|
|
|
|
|
export function createDb({
|
|
|
|
db,
|
|
|
|
getLogger,
|
|
|
|
}: Pick<IUnleashConfig, 'db' | 'getLogger'>): Knex {
|
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,
|
2022-04-07 20:55:56 +02:00
|
|
|
connection: {
|
|
|
|
...db,
|
|
|
|
application_name: db.applicationName,
|
|
|
|
},
|
2021-02-04 14:14:46 +01:00
|
|
|
pool: db.pool,
|
2021-04-22 10:07:10 +02:00
|
|
|
searchPath: db.schema,
|
2021-02-17 15:24:43 +01:00
|
|
|
asyncStackTraces: true,
|
2020-04-13 22:38:46 +02:00
|
|
|
log: {
|
2021-08-12 15:04:37 +02:00
|
|
|
debug: (msg) => logger.debug(msg),
|
|
|
|
warn: (msg) => logger.warn(msg),
|
|
|
|
error: (msg) => logger.error(msg),
|
2020-04-13 22:38:46 +02:00
|
|
|
},
|
2014-11-14 15:06:53 +01:00
|
|
|
});
|
2021-04-22 10:07:10 +02:00
|
|
|
}
|
2021-06-17 20:33:34 +02:00
|
|
|
|
|
|
|
// for backward compatibility
|
2021-04-22 10:07:10 +02:00
|
|
|
module.exports = {
|
|
|
|
createDb,
|
2016-05-01 22:53:09 +02:00
|
|
|
};
|