diff --git a/data/pokedex.sql b/data/pokedex.sql new file mode 100644 index 0000000..cef499a --- /dev/null +++ b/data/pokedex.sql @@ -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'); diff --git a/data/schema.sql b/data/schema.sql index e69de29..a740266 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -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) +); \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index bba5463..0000000 --- a/index.js +++ /dev/null @@ -1,11 +0,0 @@ -const express = require('express') -const app = express() -const port = 3000 - -app.get('/', (req, res) => { - res.send('Hello World!') -}) - -app.listen(port, () => { - console.log(`Example app listening at http://localhost:${port}`) -}) \ No newline at end of file diff --git a/rest/index.js b/rest/index.js index bba5463..05fe89c 100644 --- a/rest/index.js +++ b/rest/index.js @@ -1,6 +1,8 @@ const express = require('express') const app = express() const port = 3000 +let mysql = require('mysql'); +let pass = ''; app.get('/', (req, res) => { res.send('Hello World!') @@ -8,4 +10,30 @@ app.get('/', (req, res) => { app.listen(port, () => { console.log(`Example app listening at http://localhost:${port}`) -}) \ No newline at end of file +}) + +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; + +} \ No newline at end of file diff --git a/web/index.html b/web/index.html index 1de928b..ac24baf 100644 --- a/web/index.html +++ b/web/index.html @@ -4,6 +4,7 @@ Document +

Hello Pokemon!

diff --git a/web/script.js b/web/script.js new file mode 100644 index 0000000..43a3095 --- /dev/null +++ b/web/script.js @@ -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 => `
${pokedex.customerNumber}: ${customer.customername}
`).join("") +// )