I’ve updated SQLAlchemy to 0.6 but it broke everything. I’ve noticed it returns tuple not a dictionary anymore. Here’s a sample query:
query = session.query(User.id, User.username, User.email).filter(and_(User.id == id, User.username == username)).limit(1)
result = session.execute(query).fetchone()
This piece of code used to return a dictionary in 0.5.
My question is how can I return a dictionary?
This should work:
dict(zip(['id','username','email'],result))(or you could use a dictionary comprehension if you’re on Python 3.x).Also, you don’t need to call
session.executeon asession.queryobject. You’ll want to use the.one()method on it instead. This also obviates the need for the.limit(1)call hanging off the end of your query.