Factor out the database query into separate entity