2016-10-16 02:59:54 +05:30
|
|
|
const pgp = require('pg-promise')();
|
|
|
|
|
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];
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-07 15:17:05 -08:00
|
|
|
const client = pgp(dbOptions);
|
2016-10-16 02:59:54 +05:30
|
|
|
|
|
|
|
|
if (dbOptions.pgOptions) {
|
|
|
|
|
for (const key in dbOptions.pgOptions) {
|
|
|
|
|
client.pg.defaults[key] = dbOptions.pgOptions[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return client;
|
|
|
|
|
}
|