Skip to content

Commit

Permalink
Merge pull request #16 from danielwestendorf/pg-options
Browse files Browse the repository at this point in the history
Add support for passing a database URL and other PostgreSQL options
  • Loading branch information
esbenp authored Jan 8, 2018
2 parents eb6c923 + 55dee0d commit 8c228bc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ module.exports = {
}
```

Optionally, you can specify a database url by specifying a `connectionString`.

To install the necessary database tables, run `db:migrate`. You can also destroy the database by running `db:destroy`.

## Storage
Expand Down
37 changes: 30 additions & 7 deletions src/db/pgsql.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,37 @@ var utils = require('../utils')
var pg = require('pg')

function createPostgresDb(options = {}) {
function parseConfig() {
var config = {};

if (options.connectionString != undefined) {
config.connectionString = options.connectionString;
} else {
config.user = options.user;
config.host = options.host || 'localhost';
config.database = options.database;
config.password = options.password;
config.port = options.port || 5432;
}

if (options.ssl != undefined) {
config.ssl = options.ssl;
}

if (options.types != undefined) {
config.types = options.types;
}

if (options.statement_timeout != undefined) {
config.statement_timeout = options.statement_timeout;
}

return config;
};


return function (pdfBotConfiguration) {
var db = new pg.Client({
user: options.user,
host: options.host || 'localhost',
database: options.database,
password: options.password,
port: options.port || 5432,
})
var db = new pg.Client(parseConfig());
db.connect()

var createDbMethod = function (func) {
Expand Down

0 comments on commit 8c228bc

Please sign in to comment.