Prototype of auto-reconnect functionality

PoC, totally untested yet
I think `db` should be taken from previously closed connection (if any)