Serialization with Python & Flask-SQLAlchemy

Published: 30 June 2023
on channel: Dan's Tutorials
614
11

copy and paste scripts:

Get field names:
[col.name for col in Table.__table__.columns]

Serialize a table (convert it to a JSON (python dictionary) by converting each record to a list that contains a dictionary holding key:value pairs of the field name and the data the cell holds eg. Table = [{id: 1, "name": "James", "dob": "1/2/2023", "age": 190}, {id: 2, "name": "Batholomew", "dob": "35/2/1066", "age": -9}]):
with app.app_context(): [{col.name: getattr(record, col) for col in Table.__table__.columns} for record in Table.query.all()]


On this page of the site you can watch the video online Serialization with Python & Flask-SQLAlchemy with a duration of hours minute second in good quality, which was uploaded by the user Dan's Tutorials 30 June 2023, share the link with friends and acquaintances, this video has already been watched 614 times on youtube and it was liked by 11 viewers. Enjoy your viewing!