2018-09-09 17:22:44 -04:00
|
|
|
/**
|
|
|
|
* Expose query interface to database pool
|
|
|
|
*
|
|
|
|
* - connection details must be set in environment variables, default to:
|
|
|
|
* PGHOST='localhost'
|
|
|
|
* PGUSER=process.env.USER
|
|
|
|
* PGDATABASE=process.env.USER
|
|
|
|
* PGPASSWORD=null
|
|
|
|
* PGPORT=5432
|
|
|
|
*/
|
2018-09-30 11:17:31 -04:00
|
|
|
import pg from 'pg-promise';
|
2018-09-09 17:22:44 -04:00
|
|
|
|
2018-09-30 11:17:31 -04:00
|
|
|
// pg-promise, can provide initialisation options
|
|
|
|
const pgp = pg();
|
2018-09-30 15:27:53 -04:00
|
|
|
// database connection (default to env vars)
|
|
|
|
const db = pgp({
|
|
|
|
'host': process.env.PGHOST,
|
2019-08-09 13:49:43 -04:00
|
|
|
'database': process.env.PGDATABASE,
|
2018-09-30 15:27:53 -04:00
|
|
|
'user': process.env.PGUSER,
|
|
|
|
'password': process.env.PGPASSWORD,
|
2019-08-09 13:49:43 -04:00
|
|
|
'port': parseInt(process.env.PGPORT)
|
2018-09-30 15:27:53 -04:00
|
|
|
});
|
2018-09-09 17:22:44 -04:00
|
|
|
|
2018-09-30 11:17:31 -04:00
|
|
|
export default db;
|