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
28 changes: 28 additions & 0 deletions data/pokedex.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE TABLE IF NOT EXISTS Pokemon (
ID INT AUTO_INCREMENT,
Name VARCHAR(15),
PRIMARY KEY (ID)
);

CREATE TABLE IF NOT EXISTS PokeTypes (
ID INT AUTO_INCREMENT,
Type VARCHAR(15),
PRIMARY KEY (ID)
);

CREATE TABLE IF NOT EXISTS PokeIndex (
ID INT AUTO_INCREMENT,
PokemonID INT,
Type1 INT,
Type2 INT,
PRIMARY KEY (ID),
FOREIGN KEY (PokemonID) REFERENCES Pokemon(ID),
FOREIGN KEY (Type1) REFERENCES PokeTypes(ID),
FOREIGN KEY (Type2) REFERENCES PokeTypes(ID)
);

SELECT * FROM PokeIndex;
SELECT * FROM PokeTypes;
SELECT * FROM Pokemon;

INSERT INTO PokeTypes VALUES (1, 'normal'), (2, 'fire'), (3, 'water'), (4, 'electric'), (5, 'grass'), (6, 'ice'), (7, 'fighting'), (8, 'poison'), (9, 'ground'), (10, 'flying'), (11, 'psychic'), (12, 'bug'), (13, 'rock'), (14, 'ghost'), (15, 'dragon'), (16, 'dark'), (17, 'steel'), (18, 'fairy');
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.

We generally don't include insertion statements in the schema

22 changes: 22 additions & 0 deletions data/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE TABLE IF NOT EXISTS Pokemon (
ID INT AUTO_INCREMENT,
Name VARCHAR(15),
PRIMARY KEY (ID)
);

CREATE TABLE IF NOT EXISTS PokeTypes (
ID INT AUTO_INCREMENT,
Type VARCHAR(15),
PRIMARY KEY (ID)
);

CREATE TABLE IF NOT EXISTS PokeIndex (
ID INT AUTO_INCREMENT,
PokemonID INT,
Type1 INT,
Type2 INT,
PRIMARY KEY (ID),
FOREIGN KEY (PokemonID) REFERENCES Pokemon(ID),
FOREIGN KEY (Type1) REFERENCES PokeTypes(ID),
FOREIGN KEY (Type2) REFERENCES PokeTypes(ID)
);
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.

You can remove one of the two sql files, they both hold the same data

11 changes: 0 additions & 11 deletions index.js

This file was deleted.

30 changes: 29 additions & 1 deletion rest/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
const express = require('express')
const app = express()
const port = 3000
let mysql = require('mysql');
let pass = '';

app.get('/', (req, res) => {
res.send('Hello World!')
})

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

app.get("/pokedex", async (req, res) => {
let pokedexData = await getPokedexData();
res.send(pokedexData);
})

async function getPokedexData() {

let conn = mysql.createConnection({
host: "localhost",
user: "",
password: pass,
database: "pokedex"
});

let data = new Promise((resolve, reject) => {
conn.query("SELECT * FROM Pokemon", (err, result, fields) => {
(err) ? reject(err) : resolve(result);
})
})

conn.end();

return data;

}
1 change: 1 addition & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="script.js"></script>
</head>
<body>
<p>Hello Pokemon!</p>
Expand Down
6 changes: 6 additions & 0 deletions web/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fetch("http://localhost:3000/pokedex")
.then(response => response.json())
.then(console.log('success'))
// .then(customers =>
// document.getElementById("customers").innerHTML = customers.map(customer => `<div>${pokedex.customerNumber}: ${customer.customername}</div>`).join("")
// )