This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> INSERT INTO school (name, country, capacity) | |
-> VALUES ('Beauxbatons Academy of Magic', 'France', 550), | |
-> ('Castelobruxo', 'Brazil', 380), | |
-> ('Durmstrang Institute', 'Norway', 570), | |
-> ('Hogwarts School of Witchcraft and Wizardry', 'United Kingdom', 450), | |
-> ('Ilvermorny School of Witchcraft and Wizardry', 'USA', 300), | |
-> ('Koldovstoretz', 'Russia', 125), | |
-> ('Mahoutokoro School of Magic', 'Japan', 800), | |
-> ('Uagadou School of Magic', 'Uganda', 350); | |
Query OK, 8 rows affected (0,00 sec) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require("http"); | |
const url = require("url"); | |
const port = 8000; | |
const requestHandler = (request, response) => { | |
if (request.url === "/") { | |
response.end("Please provide name and city parameters si l'url"); | |
} else { | |
let queryS = url.parse(request.url, true).query; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const { response } = require("express"); | |
const app = express(); | |
const port = 3000; | |
app.get("/", (request, response) => { | |
response.send("Bienvenue sur Express"); | |
}); | |
app.get("/api/movies", (req, res) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const app = express(); | |
const port = 3000; | |
const connection = require("./conf"); | |
app.get("/api/employees", (req, res) => { | |
connection.query("SELECT * from employee", (err, results) => { | |
if (err) { | |
res.status(500).send(err); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const app = express(); | |
const port = 3000; | |
const connection = require("./conf"); | |
// Support JSON-encoded bodies | |
app.use(express.json()); | |
// Support URL-encoded bodies | |
app.use( | |
express.urlencoded({ | |
extended: true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.put("/api/movies/:id", (req, res) => { | |
const idMovie = req.params.id; | |
const formData = req.body; | |
connection.query( | |
"UPDATE movie SET ? WHERE id = ?", | |
[formData, idMovie], | |
(err) => { | |
if (err) { | |
console.log(err); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.delete("/api/movies/:id", (req, res) => { | |
const idMovie = req.params.id; | |
connection.query("DELETE FROM movie WHERE id = ?", [idMovie], (err) => { | |
if (err) { | |
console.log(err); | |
res.status(500).send("Erreur lors de la suppression d'un film"); | |
} else { | |
res.sendStatus(200); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get All | |
app.get("/api/movies", (req, res) => { | |
let sql = "SELECT * FROM movie"; | |
const sqlValues = []; | |
if (req.query.rating) { | |
sql += " WHERE rating = ?"; | |
sqlValues.push(req.query.rating); | |
} | |
if (req.query.genre) { | |
sql += " WHERE genre = ?"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> SELECT firstname, lastname, role, name FROM player JOIN wizard ON player.wizard_id=wizard.id JOIN team ON player.team_id=team.id ORDER BY name ASC, role ASC, lastname ASC, firstname ASC; | |
+-------------+-----------------+--------+------------+ | |
| firstname | lastname | role | name | | |
+-------------+-----------------+--------+------------+ | |
| Sirius | Black | beater | Gryffindor | | |
| Lavender | Brown | beater | Gryffindor | | |
| Seamus | Finnigan | beater | Gryffindor | | |
| Rubeus | Hagrid | beater | Gryffindor | | |
| Alice | Longbottom | beater | Gryffindor | | |
| Minerva | McGonagall | beater | Gryffindor | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT t.name, COUNT(*) AS nb_joueurs FROM player p JOIN team t ON t.id=p.team_id GROUP BY team_id ORDER BY nb_joueurs DESC; | |
+------------+------------+ | |
| name | nb_joueurs | | |
+------------+------------+ | |
| Gryffindor | 36 | | |
| Slytherin | 21 | | |
| Ravenclaw | 15 | | |
| Hufflepuff | 12 | | |
+------------+------------+ | |
4 rows in set (0,00 sec) |