Relational Databases and sqlite

So far, our hello world application is static - that is, we’ve defined the data that is shown to the user (or the “hello world”), and it can’t change based on user input. We can also do this using just standard HTML. The power of using a programming language like Python to create a web application is that we can make it dynamic - that is, responding to user input. We need a place to be able to store user data that we capture, so we need to incorporate a “persistence layer”. Luckily, there are a lot of systems out there that handle these concerns for us, and provide scalable ways to store and retrieve large amounts of information. One of the most popular types of these systems in web application development are relational databases, or more commonly just referred to as databases. These are different from the databases you might have learned about in library school like Web of Science!

Relational Databases

Relational database management systems (RDBMS, or more simply, relational databases) are systems that are used to store and retrieve data, and allow the data to be structured such that we can create relationships between the data. So we can do things like store data about students, store data about courses, and define relationships that connect students to the courses they are taking.

The basic structure of relational databases are tables, rows, columns. Think of a relational database as many spreadsheets, where each spreadsheet is a table, and consists of many rows and columns. Each table represents a thing that we want to store data about – maybe a student, a course, or a purchase. Each column in a table corresponds to a different piece of data that we’d like to collect about that thing. So columns in a student table could be: first name, last name, address, major, student number. Each row in a table corresponds to one record in that table. So for a student table, each row would be data for a different student, and include most or all of the data we defined in the columns for a student.

To interact with most relational databases, we use structured query language or SQL. With SQL, we can create/retrieve/update/delete (also sometimes referred to as CRUD) new databases, tables, or rows in a table. We can do this directly using a database client, or we can have our web application interact with the database. We will see examples of both.

sqlite

There are many different relational databases available to use. Some examples of popular ones are MySQL, Postgresql, and Microsoft Access. Usually you can interact with any of these databases with any programming language using a library for that specific database that handles making connections and sending queries/receiving data back.

For this workshop, we’re going to use SQLite, which is a lightweight database that stores its data in a single file (usually ending in .db). This is in contrast to something like MySQL, which is a large database that offers a lot of additional functionality and scalability, but also requires more setup overhead. But the ways of interacting with both MySQL and SQLite are generally the same, so a lot of the things that you learn about today with SQLite can be applied when using something like MySQL in the future.