refactor db access from utils.py