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
48 changes: 48 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//const Sequelize = require('sequelize');

//const Sequelize = new Sequelize( {
//dialect: 'sqlite',
// storage: 'movies.db'

//});

//(async () => {

//}) ();

let mysql = require("mysql");

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

con.connect(err => {
if(err) {
throw err;}
} )

let id = 2
let name = "Pikachu"
let img = "myurl2";

console.log(`INSERT INTO pokemon(id, name, img) VALUES (${id}, ${name}, ${img});`)
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.

Great start, you are generating sql statements correctly. The next step is to use con.query to run the statements in the database


id = 3
name = "Squirtle"
img = "myurl3"

console.log(`INSERT INTO pokemon (id, name, img) VALUES (${id}, ${name}, ${img});`)

//con.query("SELECT * FROM pokemon", err, result, fields) => {

//con.query(`INSERT INTO pokemon (id, name, img) VALUES ("${id}", "${name}", "${img}")`,(err, result, fields) => {

///if(err)
///throw err,


//cons
//}
25 changes: 25 additions & 0 deletions data/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


CREATE DATABASE Pokemon;

CREATE TABLE Pokemon (
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.

Schema looks good, only suggestion is to name your database or table something different. You don't want them to share the name pokemon

ID SMALLINT,
NAME VARCHAR(255),
TYPE VARCHAR (255)
);

CREATE TABLE Types(
type_ID INT PRIMARY KEY NOT NULL auto_increment,
type VARCHAR(255) NOT NULL,
);

CREATE TABLE pokemon_type (
pokemon_type_id INT PRIMARY KEY NOT NULL auto_increment,
type_ID INT NOT NULL,
pokemon_id INT NOT NULL,

);

SELECT * FROM Pokemon;
SELECT * FROM Types;
SELECT * FROM pokemon_type;
42 changes: 39 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
//database: "pokemon"



const express = require('express')
let mysql = required("mysql");
const app = express()
const port = 3000

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

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

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

async function getPokedex() {

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

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

})

con.end();

return data;



getPokedex().then(console.log);

}
154 changes: 147 additions & 7 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
},
"homepage": "https://github.com/code-differently/Pokedex-App#readme",
"dependencies": {
"express": "^4.17.1"
}
"express": "^4.17.1",
"sequelize": "^5.22.3"
},
"keywords": []
}
Loading