Add query function to db which will retry when connection is lost.