* Suppress Test Logs This will reduce some of the noise in the tests logs. * replace deprecated buffer * remove deprecation warnings * fix geopoint * Fix GraphQL * postgres warnings
29 lines
693 B
JavaScript
29 lines
693 B
JavaScript
const parser = require('./PostgresConfigParser');
|
|
|
|
export function createClient(uri, databaseOptions) {
|
|
let dbOptions = {};
|
|
databaseOptions = databaseOptions || {};
|
|
|
|
if (uri) {
|
|
dbOptions = parser.getDatabaseOptionsFromURI(uri);
|
|
}
|
|
|
|
for (const key in databaseOptions) {
|
|
dbOptions[key] = databaseOptions[key];
|
|
}
|
|
|
|
const initOptions = dbOptions.initOptions || {};
|
|
initOptions.noWarnings = process && process.env.TESTING;
|
|
|
|
const pgp = require('pg-promise')(initOptions);
|
|
const client = pgp(dbOptions);
|
|
|
|
if (dbOptions.pgOptions) {
|
|
for (const key in dbOptions.pgOptions) {
|
|
pgp.pg.defaults[key] = dbOptions.pgOptions[key];
|
|
}
|
|
}
|
|
|
|
return { client, pgp };
|
|
}
|