More db code refactoring. Make a generic export db function