Refactor large amount of db utils and place them in sentry.db