Factored db connection logic into common/djangoapps/util/query.py