Search⌘ K
AI Features

Looking into the Database

Explore how to interact with your database using the Flask Shell by initializing the app context, querying tables, and updating records. Learn techniques for inspecting data without exposing unnecessary routes in your REST API, including importing ORM classes and committing changes. This lesson helps you safely access and manage backend data during development.

The API only shows game states and not usages or user stats. This is because we have no user story that needs to access those three resources. However, as developers, we might want to see into those tables. How can we do it? We might want to create separate routes that access all the tables. This may be useful at some point, but the purpose of the API is to serve the client. Until the client needs the information, it’s probably better to access it differently. Another option is to access the data using the database’s command-line interface (CLI). This requires learning how to use the sqlite3 and psql command-line interfaces. A third option, and the one we describe next, is to use the Flask Shell and push a request context.

Looking into the database using the Flask Shell

We’ll start the shell the same way we start the ...