I removed the connection variable outside the promise scope where it wasn't needed because I don't think it's of any use. You can't put the .end() call after (and outside) the promise handlers, connection won't be defined.
I tried to keep your code style. I've been doing the standardJS style recently so I have to prompt myself to add the commas :thinking: .
I'm not 100% sure what I've done with the last example works because if the promise gets rejected before the first then() block then connection will be undefined. Hopefully checking if the connection exists and has end is enough.
Lastly, I didn't touch the pool stuff because I didn't use it so I don't know what's required, if anything. I figure the pool handles the connections anyway.
I removed the connection variable outside the promise scope where it wasn't needed because I don't think it's of any use. You can't put the
.end()
call after (and outside) the promise handlers,connection
won't be defined.I tried to keep your code style. I've been doing the standardJS style recently so I have to prompt myself to add the commas :thinking: .
I'm not 100% sure what I've done with the last example works because if the promise gets rejected before the first
then()
block thenconnection
will beundefined
. Hopefully checking if theconnection
exists and hasend
is enough.Lastly, I didn't touch the pool stuff because I didn't use it so I don't know what's required, if anything. I figure the pool handles the connections anyway.