Database to CSV and vice versa