Added all db query code for goal.js