Move db stuff into a service.