rewritten quaco, using sqlalchemy