This may be more a general PG question, but asking here in case there's any HD implications/angle on

This may be more a general PG question, but asking here in case there's any HD implications/angle on it: is it advisable to cache the
Client
instance on
req
, rather than create it for each query? i.e. instead of:
const runQ = async q => {
    const client = new Client(/* options */);
    await client.connect();
    return client.query(q);
}

do:
const runQ = async (req, q) => {
    if (!req.client) {
        req.client = new Client(/* options */);
        await req.client.connect();
    }
    return req.client.query(q);
}
Was this page helpful?