1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/src/lib/db/db-pool.ts
Salvatore Novelli 7ddbff2669
feat: add "application_name" as an optional DB option #1170 (#1478)
* implemented changes to resolve issue 1170

* added applicationName to the list of db options in the documentation'

Co-authored-by: Daniele Casal <daniele.casal@lloydsbanking.com>
Co-authored-by: Sukhvinder Panesar <79143027+esspee-lbg@users.noreply.github.com>
2022-04-07 20:55:56 +02:00

31 lines
732 B
TypeScript

import { knex, Knex } from 'knex';
import { IUnleashConfig } from '../types/option';
export function createDb({
db,
getLogger,
}: Pick<IUnleashConfig, 'db' | 'getLogger'>): Knex {
const logger = getLogger('db-pool.js');
return knex({
client: 'pg',
version: db.version,
connection: {
...db,
application_name: db.applicationName,
},
pool: db.pool,
searchPath: db.schema,
asyncStackTraces: true,
log: {
debug: (msg) => logger.debug(msg),
warn: (msg) => logger.warn(msg),
error: (msg) => logger.error(msg),
},
});
}
// for backward compatibility
module.exports = {
createDb,
};