restructure repo, separate sample app from docker configs
This commit is contained in:
25
05-example-web-application/api-node/src/db.js
Normal file
25
05-example-web-application/api-node/src/db.js
Normal file
@ -0,0 +1,25 @@
|
||||
const { Pool } = require('pg');
|
||||
|
||||
const pool = new Pool();
|
||||
|
||||
// the pool will emit an error on behalf of any idle clients
|
||||
// it contains if a backend error or network partition happens
|
||||
pool.on('error', (err, client) => {
|
||||
console.error('Unexpected error on idle client', err);
|
||||
process.exit(-1);
|
||||
});
|
||||
|
||||
// async/await - check out a client
|
||||
const getDateTime = async () => {
|
||||
const client = await pool.connect();
|
||||
try {
|
||||
const res = await client.query('SELECT NOW() as now;');
|
||||
return res.rows[0];
|
||||
} catch (err) {
|
||||
console.log(err.stack);
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { getDateTime };
|
||||
Reference in New Issue
Block a user