I have a route that handles API calls for timepunches. One of the calls is to "clock_in".
router.route('/clock_in').post(managerCheck, startTimeCheck, isClockedIn, clockIn);
Each of these functions will perform it's own db connection, query the db for some info, then respond to the user or go to the next() function.
I'm using pool from 'pg-poll'.
My connection looks like this.
export const **isClockedIn** = (request, response, next) => {
const query = `select * from....`;
const values = [value1, value2];
pool.connect((err, client, release) => {
client.query(query, values, (err, result) => {
//do stuff
}
and the connection is essentially the same for all functions.
What i'd like to do is have only 1 instance of pool.connect then each function in the api call will use that connection to do their client.query. I'm just not sure how i'd set that up.
Hopefully my question is clear. All my code works, it's just not efficient since it's making multiple db connections for 1 api call.