Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions data/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
drop database IF EXISTS classicmodels;
drop database IF EXISTS pokedex ;
create database pokedex;
use pokedex;
CREATE TABLE pokemon (
pokemon_id INT PRIMARY KEY NOT NULL,
name VARCHAR(255) NOT NULL
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing image src

-- color VARCHAR(255),
-- type VARCHAR(255),
-- type2 VARCHAR(255),
-- weakness VARCHAR(255)
);
CREATE TABLE types (
type_id INT PRIMARY KEY NOT NULL auto_increment,
type VARCHAR(255) NOT NULL
-- FOREIGN KEY (type_id) REFERENCES pokemon_type(type_id)
);
CREATE TABLE pokemon_type (
pokemon_type_id INT PRIMARY KEY NOT NULL auto_increment,
type_id INT NOT NULL,
pokemon_id INT NOT NULL,
FOREIGN KEY (pokemon_id) REFERENCES pokemon(pokemon_id),
FOREIGN KEY (type_id) REFERENCES types(type_id)
);
ALTER TABLE pokemon_type ADD FOREIGN KEY(pokemon_id) REFERENCES pokemon(pokemon_id);
ALTER TABLE pokemon_type ADD FOREIGN KEY(type_id) REFERENCES types(type_id);


INSERT INTO pokemon (pokemon_id, name)
VALUES
(1,'bulbasaur'),
(2, 'ivysaur'),
(3, 'venusaur'),
(4, 'charmander'),
(5, 'charmeleon'),
(6, 'charizard'),
(7, 'squirtle'),
(8, 'wartortle'),
(9, 'blastoise'),
(10, 'caterpie');

INSERT INTO types(type)
VALUES
('fire'),
('bug'),
('grass'),
('water'),
('normal'),
('electric'),
('poison'),
('ground'),
('fairy'),
('psychic'),
('rock'),
('fighting'),
('ghost'),
('ice'),
('dragon'),
('steel'),
('dark'),
('flying');


INSERT INTO pokemon_type(type_id, pokemon_id)
VALUES
(3, 1),
(3, 2),
(3, 3),
(1, 4),
(1, 5),
(1, 6),
(4, 7),
(4, 8),
(4, 9),
(2, 10);

-- SELECT p.name, tp.type, pt.pokemon_type_id
-- FROM pokemon p
-- LEFT JOIN pokemon_type pt
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its best to delete code instead of committing commenting out code

-- ON p.pokemon_id = pt.pokemon_id
-- INNER JOIN types tp
-- ON tp.type_id = pt.type_id;

11 changes: 0 additions & 11 deletions index.js

This file was deleted.

96 changes: 89 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pokedex-app",
"version": "1.0.0",
"description": "![pickachu](https://media.giphy.com/media/xuXzcHMkuwvf2/giphy.gif)",
"main": "index.js",
"main": "rest/index.js",
"scripts": {
"test": "mocha",
"start": "node rest/index.js"
Expand All @@ -18,6 +18,9 @@
},
"homepage": "https://github.com/code-differently/Pokedex-App#readme",
"dependencies": {
"express": "^4.17.1"
"cors": "^2.8.5",
"express": "^4.17.1",
"mysql": "^2.18.1",
"node-fetch": "^2.6.1"
}
}
39 changes: 36 additions & 3 deletions rest/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
const express = require('express')
const mysql = require("mysql");
const cors = require("cors");
const app = express()
const port = 3000

app.use(cors())

app.get('/', (req, res) => {
res.send('Hello World!')
})
app.get('/pokemon', async (req, res) => {
let customerData = await getCustomerData();
res.send(customerData);
})

app.listen(port, () => {
console.log (`Example app listening at http://localhost:${port}`)
})


async function getCustomerData(){

let con = mysql.createConnection ({

password: "Pakistan@777",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you change your password haha

user: "root",
database: "pokedex",
host: "localhost",
});

let data = await new Promise ((resolve, reject) => {
con.query ("SELECT * FROM pokemon", (err, result) => {
(err) ? reject(err) : resolve(result);

})

})
con.end();

return data;

}

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
2 changes: 2 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
</head>
<body>
<p>Hello Pokemon!</p>
<div id="customers"></div>
<script src="script.js"></script>
</body>
</html>
8 changes: 8 additions & 0 deletions web/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

fetch("http://localhost:3000/pokemon")
.then(response =>response.json())
.then(customers => {
document.getElementById("customers").innerHTML = customers.map(customer => `<div>${customer.pokemon_id}: ${customer.name}</div>`).join("")
});