move db function to a individual file