* pg-promise init options * add database init options * Create PostgresInitOptions.spec.js * Update PostgresInitOptions.spec.js * Update PostgresInitOptions.spec.js * add PostgresInitOptions test * Add files via upload * linebreaks CRLF to LF * modify postgresURI to test environment * modify pg error code to 42P01 * fix reconfigureServer callback
28 lines
625 B
JavaScript
28 lines
625 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 || {};
|
|
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;
|
|
}
|