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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
40 changes: 40 additions & 0 deletions data/createTables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const mysql = require('mysql');
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.

I recommend creating your schema with a sql script. You can run the script whenever you want to recreate your database


const con = mysql.createConnection({
host: "localhost",
user: "root",
password: "*****",
database: "pokedex"
});

con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
let sql = "CREATE TABLE pokemon(id INT PRIMARY KEY NOT NULL,name VARCHAR(50),img VARCHAR(256))";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("pokemon table created...");
});
}),

con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
let sql = "CREATE TABLE types(id INT PRIMARY KEY NOT NULL,name VARCHAR(32))";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("types table created...");
});
}),

con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
let sql = "CREATE TABLE poke_type(id INT PRIMARY KEY AUTO_INCREMENT,pokeId INT NOT NULL,typeId INT NOT NULL,FOREIGN KEY (pokeId) REFERENCES pokemon(id),FOREIGN KEY (typeId) REFERENCES type(id))";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("mapping table created...");
});

con.end ()
});
24 changes: 24 additions & 0 deletions data/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- CREATE DATABASE pokedex;
CREATE DATABASE pokedex;
USE pokedex;

CREATE TABLE pokemon(
id INT PRIMARY KEY NOT NULL,
name VARCHAR(50),
img VARCHAR(256)
);

CREATE TABLE types(
id INT PRIMARY KEY 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.

Recommend using auto increment here as well

name VARCHAR(32)
);

CREATE TABLE poke_type(
id INT PRIMARY KEY AUTO_INCREMENT,
pokeId INT NOT NULL,
typeId INT NOT NULL,
FOREIGN KEY (pokeId) REFERENCES pokemon(id),
FOREIGN KEY (typeId) REFERENCES types(id)
);

SELECT pokemon.ID AS id, name,types.type, img FROM pokemon join poke_type on pokemon.id = poke_type.pokeId join types on poke_type.typeId = types.id order by pokeId;
11 changes: 0 additions & 11 deletions index.js

This file was deleted.

Loading