completed sqlalchemy conversion