colouring-montreal/app/src/db.ts

25 lines
636 B
TypeScript
Raw Normal View History

/**
* 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-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,
'database': process.env.PGDATABASE,
2018-09-30 15:27:53 -04:00
'user': process.env.PGUSER,
'password': process.env.PGPASSWORD,
'port': parseInt(process.env.PGPORT)
2018-09-30 15:27:53 -04:00
});
2018-09-30 11:17:31 -04:00
export default db;