forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgresClient.js
36 lines (28 loc) · 892 Bytes
/
PostgresClient.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 (process.env.PARSE_SERVER_LOG_LEVEL === 'debug') {
const monitor = require('pg-monitor');
if (monitor.isAttached()) {
monitor.detach();
}
monitor.attach(initOptions);
}
if (dbOptions.pgOptions) {
for (const key in dbOptions.pgOptions) {
pgp.pg.defaults[key] = dbOptions.pgOptions[key];
}
}
return { client, pgp };
}