Express middleware for db connection handling