I made a query to search for a user. It worked!
But I tried to make another query, he gave this message
Error: Cannot use a pool after calling end on the pool
Because every time I make a connection, I close it later, and it seems that once it is closed it does not reopen.
I'm using nodejs 10 with postgres
This is my method:
return new Promise( (resolve, reject) => {
const { pool, errorHandler } = deps
const query = "SELECT * FROM public.usuario WHERE cpf = $1"
const queryData = [ cpf ]
pool.connect()
pool.query( query, queryData, (error, results) => {
if(error){
errorHandler(error, 'Não foi possível encontrar usuário com cpf ${cpf}', reject)
return false
}
if( results.rowCount > 0 ){
resolve({ usuario: results.rows })
}else{
resolve({msg: 'Usuário não encontrado'})
}
})
pool.end()
})
Notice that every time I have access, I pass the connect()
method, but it is not working
And you still have this message:
Error: Called end on pool more than once