19.10 Practical Exercise
Exercise 19.1
1. Creating a Database with SQLAlchemy ORM:
Create a SQLite database using SQLAlchemy with the following tables:
- Users (columns: id, name, email, country)
- Orders (columns: id, user_id, product, amount)
Here is the starter code for the exercise:
2. Inserting Data into the Tables:
Insert the following data into the tables you created in the previous exercise:
- Users: (1, 'John', 'john@example.com', 'USA'), (2, 'Jane', 'jane@example.com', 'Canada')
- Orders: (1, 1, 'Apples', 10), (2, 2, 'Oranges', 20)
Remember to use a session to add and commit the data to the database.
3. Querying the Database:
Write a query to fetch all orders made by 'John'. Use a JOIN operation to get the data from both tables. Print the product and amount for each order.
4. Updating Data:
Write a query to update the amount of 'Apples' ordered by 'John&apos...