Generalize the conversion between database and phoenix objects