-
Notifications
You must be signed in to change notification settings - Fork 516
Week1 README
Information is something that adds knowledge. It tells you something you 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: you 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 you 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 you to store structured information and at a later point in time retrieve that information again. You can ask the database: "Who was walking on the Sarphatistraat on november the 10th 2019?" and the database will tell us: "Wouter Kleijn".
You abstract (generalize) to make sense of the world. You 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". You speak of a dog called Bello, and since it's a dog you also know that Bello is an animal and a pet. This is not something that Bello will tell you, 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. You can think of a pet as an entity that has a relationship to another entity human, its owner. More formally you can say a human owns zero or more pets.
When creating an application you need to think of all the entities and their relationships that are relevant to our application, you call this the application's domain. Together these entities and relationships form the domain model for your application.
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 you just consider these two properties (information storage and retrieval) you could implement a database using just a JavaScript array:
- Information storage. Pushing onto the array adds knowledge:
const musicians = [
"John Coltrane",
"Miles Davis",
"Thelonious Monk",
"Sonny Rollins"
];
musicians.push("Steve Lehman");
- Information access. Using the
[]
operator you can access what was previously stored:
console.log(musicians[0]); // prints: 'John Coltrane'
While this JavaScript database is a nice and simple example, You will focus primarily on much more sophisticated relational databases, in particular MySQL.
In a relational database you model entities in terms of tables (think spreadsheets) and you model relationships between those tables. A relationship can be one of the three following types:
- One-to-one, for example: "a person has one profile"
- One-to-many, for example: "in a house live zero or more people"
- Many-to-many, for example: "a musician can play one or more instruments and an instrument can be played by one or more musicians"
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 your web application talking to the database. The reason why you would want to use a database is that you can store information in a reliable and structured way. The database will ensure your information is stored safely (if setup correctly), with a high degree of reliability. The database also allows you to structure your information in such a way that we're able to find what we're looking for.