Greetings,
I've searched the group archives and looked at StackOverflow (sorry!) and
couldn't come up with the canonical way to convert a row object to a dict.
Here are some code snippets:
Base = declarative_base()
class Station(
Base,
):
__tablename__ = 'stations'
id = Column(Integer, primary_key = True)
created_at_id = Column(Integer, ForeignKey('synchronizations.id'))
extension = Column(String, unique = True, nullable = False)
stations = db.session.query(Station)
for s in stations:
d = dict(s)
TypeError: 'Station' object is not iterable
If I try the _asdict()
stations = db.session.query(Station)
for s in stations:
d = s._asdict()
AttributeError: 'Station' object has no attribute '_asdict'
Clearly I am missing something.
Any pointers?
Thanks!
-m
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.