I need to execute another query while iterating the first query as follows, but I keep getting an error "const error = this._ending ? new Error('Connection terminated') : new Error('Connection terminated unexpectedly')". The query is not a final query. I am just testing it out.
const client = new Client(credentials)
await client.connect()
const userQuery = await client.query('select c.* from clients c')
const rows = userQuery.rows
rows.forEach(async row => {
console.log("user", row)
const orderQuery = await client.query(`select o.created from orders o where o."userId" = ${row.id} order by o.created desc limit 1`)
const orderRows = orderQuery.rows
orderRows.forEach(order => {
console.log(order)
})
})
await client.end()
is there a way to execute another query while iterating the first query?