Skip to content

Latest commit

 

History

History
34 lines (19 loc) · 2.73 KB

README.md

File metadata and controls

34 lines (19 loc) · 2.73 KB

Text

Before you begin!

A lot of the code we'll demonstrate in this level's lessons will be required to complete the milestone target in this level.

When you're following along (you are following along and writing these programs, aren't you?) with these lessons, keep all the code you write in separate files in the same GitHub repository. This will make working on the milestone target and submitting a working solution much simpler.

Why Databases?

When you build a web application, say like our to-do manager, you don't want the data you enter to vanish the moment you close the web page.

Instead, it has to be saved somewhere, so we can access it whenever we want, from any internet-connected machine in the world. To accomplish this, we have to tell our application server to persist the changes to its storage. Now, we can do this by simply writing it into a file and then reading from it. That's one way.

However, this is a very crude way of going about things. It is because:

  1. How will you read back this to-do? Where does one to-do begin and another end?
  2. How will you update a single to-do without rewriting the entire file every time?
  3. How can multiple users work on the same file without overwriting each other's changes?
  4. How can you get quick reports even as the file grows to many gigabytes?

These questions are not trivial, even though they may appear so at first blush. There is a huge body of computer science literature around data storage and manipulation, and it has spawned large commercial offerings from companies like Oracle and Microsoft.

Thankfully, we don't have to redo any of that work ourselves nor rely on closed-source commercial software. Instead, we'll use PostgreSQL, a powerful and open-source database used by some of the largest SaaS companies in the world.

Basics of relational databases

A database is essentially a collection of tables. Say if you're building software to manage inventory and accounts for a supermarket, then the database will contain a table to hold the list of items and their details, another table to save all the sales invoices, and tables to store customer and vendor info and so on.

We can then ask the database questions like "what was the total sale in the last week?" or "which customers bought the most amount of grocery this year?". These queries can pull in data from different tables in the database, which we call a join operation. All of this is done using a language called SQL, which is short for Structured Query Language.

But we won't be learning much SQL in this course. Instead, we'll look at Sequelize, which lets us talk to the database through JavaScript and not directly write SQL ourselves.

But before we go there, let's set up PostgreSQL on your machine.