Created
November 20, 2017 08:47
-
-
Save mattonit/ae6a8fa2c2cf9cca8eed314ba62c7ee7 to your computer and use it in GitHub Desktop.
Hapi PgSQL Connect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const { Client } = require('pg'); | |
const Database = { | |
register: (server, options, next) => { | |
const db = new Client({ | |
user: 'db_user', | |
host: 'host', | |
database: 'db_name', | |
password: 'db_pass', | |
port: 5432, // default PgSQL port | |
ssl: true // force SSL | |
}) | |
db.connect() | |
server.app.PgSQL = function(){ | |
return db; | |
}; | |
next(); | |
} | |
} | |
Database.register.attributes = { | |
name: 'Database', | |
version: '1.0.0' | |
} | |
module.exports = Database; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment