move all db related code to db