Skip to content

Week1 README

Frank Versnel edited this page Nov 16, 2019 · 5 revisions

What is information?

Information is something that adds knowledge. It tells us something we didn't know before. For example:

"At 9:30 on sunday november 10th 2019 Wouter Kleijn was walking on the Sarphatistraat in Amsterdam."

This is information because it adds knowledge: we now know where Wouter was at a particular point in time. For a computer this might be a bit difficult to understand though because it is just an English sentence. It's much easier if we structure it this way:

  • Address:
    • Street: Sarphatistraat
    • City: Amsterdam
  • Who: Wouter Kleijn
  • When: 2019-11-10T09:30:00+01:00 (+01:00 refers to the Amsterdam timezone)
  • Activity: Walking

A database will allow us to store structured information and at a later point in time retrieve that information again. We can ask the database: "Who was walking on the Sarphatistraat on november the 10th 2019?" and the database will tell us: "Wouter Kleijn".

Entities & Relationships

We abstract to make sense of the world. We do it everywhere, all the time. Even without thinking about it. As Zachery Tellman states: "To abstract is to treat things which are different as equivalent". We speak of a dog called Bello, and since it's a dog we also know that Bello is an animal and a pet. This is not something that Bello will tell us, we humans made all this up. Dog, animal, pet, humans, all these are abstractions.

One way of abstracting is to think of entities and their relationships. An entity is an abstraction. It represents a certain category of things, like: humans, women, men, animals, pets, broken bicycles, chairs, music, teachers, chewing gum, and planets. We can think of a pet as an entity that has a relationship to another entity human, its owner. More formally we can say a human owns zero or more pets.

When creating an application we need to think of all the entities and their relationships that are relevant to our application, we call this the application's domain. Together these entities and relationships form the domain model for our application.

What is a database?

A database's primary purpose is to provide a mechanism for storing and retrieving structured information. There are many different types of databases but they all provides these two capabilities.

If we just consider these two properties (information storage and retrieval) we could implement a database using just a JavaScript array:

  1. Information storage. Pushing onto the array adds knowledge:
const musicians = [
  "John Coltrane",
  "Miles Davis",
  "Thelonious Monk",
  "Sonny Rollins"
];

musicians.push("Steve Lehman");
  1. Information access. Using the [] operator we can access what was previously stored:
console.log(musicians[0]); // prints: 'John Coltrane'

While this JavaScript database is a nice and simple example, we'll focus primarily on much more sophisticated relational databases, in particular MySQL.

In a relational database we model entities in terms of tables (think spreadsheets) and we model relationships between those tables. A relationship can be one of the three following types:

  1. One-to-one, for example: "a person has one profile"
  2. One-to-many, for example: "in a house live zero or more people"
  3. Many-to-many, for example: "a musician can play one or more instruments and an instrument can be played by one or more musicians"

What is the role of a database in an application?

A database setup typically involves two components, a server and a client. The server is the actual database management system and runs as a process on a machine either on your computer or on another computer in a data center somewhere. The client is a program that talks to the database management system (the server), so it has to know where that server is running. The client then creates a TCP connection (if you're interested in some more details look up the TCP protocol, otherwise you can forget about TCP for now) to the server. To do this the client needs to know:

  • the server's address
    • an ip address like 192.168.1.5
    • or a name like my-db-server
  • a username
  • a password
  • the name of the database

The client would be our web application talking to the database. The reason why we would want to use a database is that we can store information in a reliable and structured way. The database will ensure our information is stored safely (if setup correctly), with a high degree of reliability. The database also allows us to structure our information in such a way that we're able to find what we're looking for.

Clone this wiki locally