Skip to content

Commit 8c228bc

Browse files
authored
Merge pull request #16 from danielwestendorf/pg-options
Add support for passing a database URL and other PostgreSQL options
2 parents eb6c923 + 55dee0d commit 8c228bc

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ module.exports = {
329329
}
330330
```
331331

332+
Optionally, you can specify a database url by specifying a `connectionString`.
333+
332334
To install the necessary database tables, run `db:migrate`. You can also destroy the database by running `db:destroy`.
333335

334336
## Storage

src/db/pgsql.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,37 @@ var utils = require('../utils')
55
var pg = require('pg')
66

77
function createPostgresDb(options = {}) {
8+
function parseConfig() {
9+
var config = {};
10+
11+
if (options.connectionString != undefined) {
12+
config.connectionString = options.connectionString;
13+
} else {
14+
config.user = options.user;
15+
config.host = options.host || 'localhost';
16+
config.database = options.database;
17+
config.password = options.password;
18+
config.port = options.port || 5432;
19+
}
20+
21+
if (options.ssl != undefined) {
22+
config.ssl = options.ssl;
23+
}
24+
25+
if (options.types != undefined) {
26+
config.types = options.types;
27+
}
28+
29+
if (options.statement_timeout != undefined) {
30+
config.statement_timeout = options.statement_timeout;
31+
}
32+
33+
return config;
34+
};
35+
36+
837
return function (pdfBotConfiguration) {
9-
var db = new pg.Client({
10-
user: options.user,
11-
host: options.host || 'localhost',
12-
database: options.database,
13-
password: options.password,
14-
port: options.port || 5432,
15-
})
38+
var db = new pg.Client(parseConfig());
1639
db.connect()
1740

1841
var createDbMethod = function (func) {

0 commit comments

Comments
 (0)