Skip to content

Instantly share code, notes, and snippets.

View moni-be's full-sized avatar
🏠
Working from home

moni-be

🏠
Working from home
  • France
View GitHub Profile
@moni-be
moni-be / GET en détail
Created June 21, 2020 16:55
(WCS) Express 6
REQUEST / index.js
app.get('/api/movies', (req, res) =>{
let sql = 'SELECT * from movie';
const sqlValues = [];
if(req.query.genre && req.query.rating){
sql += ' WHERE genre = "Fantasy" AND rating =3';
sqlValues.push(req.query.genre && req.push.rating);
}
connection.query(sql, sqlValues,(err, results) => {
@moni-be
moni-be / SQL avancé
Last active June 4, 2020 09:38
(WCS) Quête6 DB
1/
mysql> SELECT name, COUNT(name) AS number FROM team LEFT JOIN player ON team.id=team_id GROUP BY name ORDER BY number DESC;
+------------+--------+
| name | number |
+------------+--------+
| Gryffindor | 36 |
| Slytherin | 21 |
| Ravenclaw | 15 |
| Hufflepuff | 12 |
+------------+--------+
@moni-be
moni-be / Les jointures
Last active June 3, 2020 20:31
(WCS) Quête DB 05
1/
mysql> SELECT lastname, firstname, role, name from player join wizard on wizard.id=wizard_id join team on team.id=team_id order by name, role, lastname,firstname asc;
+-----------------+-------------+--------+------------+
| lastname | firstname | role | name |
+-----------------+-------------+--------+------------+
| Black | Sirius | beater | Gryffindor |
| Brown | Lavender | beater | Gryffindor |
| Finnigan | Seamus | beater | Gryffindor |
| Hagrid | Rubeus | beater | Gryffindor |
| Longbottom | Alice | beater | Gryffindor |
@moni-be
moni-be / Express 5
Created June 2, 2020 20:08
(WCS) Quête Node.js
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./conf');
app.use(express.json());
// Support URL-encoded bodies
app.use(express.urlencoded({
extended: true
}));
@moni-be
moni-be / Express 4
Created June 2, 2020 19:38
(WCS) Quête Node.js
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./conf');
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
app.put('/api/movies/:id', (req, res)=>{
@moni-be
moni-be / Express 3
Created June 2, 2020 17:14
(WCS)Quête Node.js
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./conf');
app.use(express.json());
// Support URL-encoded bodies
app.use(express.urlencoded({
extended: true
}));
@moni-be
moni-be / Express 2
Created June 1, 2020 21:43
(WCS)Quête Node.js
const express = require('express');
const app = express();
const port = 3000;
const connection = require('./conf');
app.get('/api/movies', (req, res) =>{
connection.query('SELECT * from movie', (err, results) => {
if (err) {
res.status(500).send('Erreur lors de la récupération des films');
} else {
@moni-be
moni-be / Express 1
Created June 1, 2020 17:13
(WCS) Quête Node.js
const express = require('express');
const app = express();
const port = 3000;
app.get('/api/movies', (request, response) => {
response.send("Récupération de tous les films");
});
app.get(`/api/movies/:id`, (request, response) => {
const id_movie = request.params.id;
@moni-be
moni-be / Serveur HTTP
Created May 31, 2020 20:46
(WCS)quête Node.js
const http = require('http');
const url = require ('url');
const port = 8000;
const requestHandler = (request, response) => {
const myParsedUrl = url.parse(`/${request.url}`,true);
const donnesUrl = myParsedUrl.query;
if (request.url === '/' || request.url === '/?name=' || request.url === '/?name=&city=' || request.url === '/?city=') {
response.end('Please provide name AND city parameters');
@moni-be
moni-be / Pratique
Created May 29, 2020 16:31
(WCS)Le protocole HTTP
### GET api.kerokuapp.com (no parameter)
GET https://http-practice.herokuapp.com/wilders
### GET api.kerokuapp.com (parameters language and page)
GET https://http-practice.herokuapp.com/wilders?language=JavaScript&page=20
###POST api.kerokuapp.com (insertion data in form-urlencoded, parameters name and language)
POST https://http-practice.herokuapp.com/wilders
Content-Type: application/x-www-form-urlencoded