wow this is ugly. hopefully there's a more sqlalchemy-friendly way to do this?