Lab 5:
Creating Databases
Welcome to the fifth lab of Term 3!
In this lab, we will learn about how we can access the data in the databases that we created and query the information.
Challenge: Create an SMS app on Anvil that uses data tables to store data.
Create a User Interface that follows Material Design guidelines
Connect to the Twilio API to add text messaging functionality
Create a database of information that your app will be using
Use databases to store phone numbers and contact information
Send messages from the server side, not the client side of the app
Reference
Querying Databases
Now that we have data in our databases, we need to be able to access the data.
We call this querying our database. We run commands to request information from the database or modify the data currently stored.
Types of Queries
Accessing a row in a table
for row in app_tables.people.search():
print(f"{row['name']} is {row['age']} years old")
Here, the search function will return the entire row in that column since no arguments were specified. The for loop will print out each row.
people_named_wolf = app_tables.people.search(name="Wolf R.")
Here, we pass an argument into the search function, where we look for any rows where the name column contains the value 'Wolf R'.
You can query tables using query operators which allow for more advanced searching functionality. See the Anvil documentation (linked in the Additional Resources below).
For example, you can query the database to get all students who are 'Active' or are over the age of 15.
Additional Resources
Resources