Week 7 A week of discoveries, databases and servers

Homework assignment of the weekend: LIRI

Day 29: Celebrating that we are halfway

It is Monday ✌🏼 and I am so excited for today’s class! Today they provided us with breakfast as we are in our halfway on the program and I didn’t realize how fast time went so fast. We started our class analyzing a code 🧐 that was a push from our teacher that created a game. This was more than 200 lines of codes which did the scrolling really tediously, 🤯 luckily he mentions the idea of having our code in different files and divided require them in one of the files 📥. By doing this, the code can be divided and read in a more agile way, so we practice this with an exercise that calls on API of actors and consoles log the result 📄, we created constructors and use require as our main goal of the exercise

We were then introduced to the idea of checking for bulls inside the responses of the API 📮. We used differently if statements that will help us showcase our outputs without errors. Finally, for tomorrow, we are going to be introduced to MySQL! I can’t wait! 

Day 30: Discovering MySQL

Today I started class by doing a whiteboard problem 📄, doing this every day can help be more prepared for more challenging problems when coding, and I manage to do it! Definitely, I can improve it but still, I was able to get close to the solution 💌.

We started class creating callback functions that really push our way of linking functions that can call other functions to execute. Here you can find some lines of code I developed for the assignment they ask us to do 📝

// Write a function that runs a function argument if
// its other argument is truthy.
function argument(argument,cb){
    if(argument){
        if(typeof cb === "function"){
            cb()
        }
        else{
            console("This is not a function")
        }
    }
}
// Write a function that accepts a function argument and
// a value, and returns a function that returns the result
// of executing the function argument with the value.
// This isn't as hard as it sounds!
function accepts(value,cb){
    if (typeof cb !== "function"){
        throw new Error ("Your second input is not a function")
    }
    return function(){
        return cb(value)
    }
}

During these exercises ✏️, we also learn how to throw an error in the case the user doesn’t provide a function, this throw errors can be customizable abe can help us build our code and understand why is not working 🤔.

But the main content of today was the introduction to MySQL to create databases, here you can find some simple code that creates tables:

-- Drops the favorite_db if it exists currently --
DROP DATABASE IF EXISTS favorite_db;
-- Creates the "favorite_db" database --
CREATE DATABASE favorite_db;


-- Make it so all of the following code will affect favorite_db --
USE favorite_db;


-- Creates the table "favorite_foods" within favorite_db --
CREATE TABLE favorite_foods (
  -- Make a string column called "food" which cannot contain null --
  food VARCHAR(30) NOT NULL,
  -- Make an numeric column called "score" --
  score INT(10)
);


CREATE TABLE favorite_songs (
  -- Make a string column called "song" which cannot contain null --
  song VARCHAR(30) NOT NULL,
  -- Make a string column called "artist" --
  artist VARCHAR(30) NOT NULL,
  -- Make an integer column called "score" --
  score INT(10)
);


CREATE TABLE favorite_movies (
  -- Create a numeric column called "id" which automatically increments and cannot be null --
  id VARCHAR(30) NOT NULL AUTO_INCREMENT,
  -- Create a string column called "movie" which cannot be null --
  movie VARCHAR(30) NOT NULL,
  -- Create a boolean column called "five_times" that sets the default value to false if nothing is entered --
  five_times BOOLEAN DEFAULT 5,
  -- Make an integer column called "score" --
  SCORE INT(10),
  -- Set the primary key of the table to id --
  PRIMARY KEY(id)
);

I have to say that learning a new language is super exciting 🥳, I’ve been loving every minute of this class and every new concept that we can immediately apply. Here are some notes from the class:

Finally, I want to share this cool concept our teacher has shared with us that can be applied to any language, CRUD, that stands for :

  • C: 📝Create, in MySQL is INSERT
  • R: 📖Read, in MySQL is SELECT
  • U: ✏️Update, in MySQL is UPDATE
  • D: ✂️Delete, in MySQL is DELETE

Day 31: Discovering MySQL

We are on the mid of the week and things are getting really interesting 🧐, we started the class reviewing the term CRUD and we continue by connecting our SQL Workbench with our Java files! This means that we can create, edit and add values to our databases inside a java file by using the package of MySQL from Node.js, here is an example

function afterConnection() {
    connection.query("SELECT * FROM songs", function (err, res) {
        if (err) throw err;
        console.log(JSON.stringify(res, null, 2));
    });
    connection.query("SELECT * FROM songs WHERE genre = ?",['Pop'], function (err, res) {
        if (err) throw err;
        console.log("GENERE")
        console.log(JSON.stringify(res, null, 2));
    });
    connection.query("SELECT * FROM songs WHERE artist = ?",['C.Tangana'],function (err, res) {
        if (err) throw err;
        console.log("ARTIST")
        console.log(JSON.stringify(res, null, 2));
}
    });

For doing so, we need to provide information about our password and hostname 🗄, and I brought out the idea of security, as we, in the future push it to our repositories. For avoiding providing our keys to everyone we first create a 👮🏼‍♀️”.gitignore” folder and then mention a field “.env”, we then create this field and add the information. (Is important to create this field before creating the document so it doesn’t showcase)

We then worked on a betting game where the user can prompt some information, we do this through the terminal:and then this is added to our database:

Day 32: Connecting external Data Bases

Another day of class started 📌, I came early to review a word guessing game to practice constructors and I have to say that is really challenging but I will still try it 👩🏼‍💻. We then continue class reviewing the connections of Java and SQL workbench.

These days we’ve been creating the content inside our databases but today we actually add a .csv file to a table we created inside MySQL workbench 🧠. We added songs from 5000 lines of data and for doing so we first created a table with the same data categories represented in the CSV provided 💾. We then do search inside that database to complete the assignment, here you can find some lines of code:

and then I was able to successfully 🥁 connect two Data Bases by joining them! We connected albums and songs which is great 🙌🏼

Day 33: Learning servers and using express

WOW! Another ✌🏼week about to end and today we learned so much! We were introduced to the idea of servers, and how they work in order to connect the front with the back end. It “listens” or reads the client request (or browser) and gives a response based on the server code pre-establish code 🏗.

Here is where we are actually overviewing the whole full stack developing a world which feels amazing 🚀, as we can start using all the languages and tools we have been learning in the past days. So, we started creating our first serves inside our own localhost using a defined port:

Then we connected the different Urls 🧩 searched by the user to show different HTML files we created and we used the package fs:

We then started reviewing code that uses the express package in order to not use the switch statements in the code, 🎫 by doing this our code is more readable and we can do multiple other prompts which opens a lot of possibilities.

Can’t wait to start next week and for this weekend homework, we need to create a database so let’s start coding! 🤹🏻‍♀️

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s

A %d blogueros les gusta esto: