SQLA and Flask: Planets Database Example -- More Queries and an API route

Опубликовано: 10 Октябрь 2024
на канале: Thomas Blum
29
1

In this video we continue our example of a simple SQLAlchemy database (just one table containing Planet data). We look a little more carefully at the queries. If we query the entire table (somewhat like a SELECT * in SQL), the result is a list of object. However, if we name specific columns we want in the query, the result is a list of "named tuples." In each case we can cast the results to a list of dictionaries. When we have objects we use __dict__, and when we have named tuples we use _asdict(). We change the query leading to our GridJS datatable, and we add a search functionality. Finally we add an API route that just dumps our the query results as JSON.