Move some db related functions out of utils