Move db to it's own thread and recreate connection if it isn't open