-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ruba week3 databases #26
base: main
Are you sure you want to change the base?
Ruba week3 databases #26
Conversation
Week 2 LESSONPLAN
delete unnecessary info and typos in homework
…ce of timing between a column having an index and a column not having one
js file to fill up big db
week 3 typos and other minor changes
clarify homework question
…-assignment Homework -> Assignment update
Fixed assignment URL
…npm_and_yarn/Week2/QA-session-content/knex-2.4.0 Bump knex from 0.21.1 to 2.4.0 in /Week2/QA-session-content
fixed lucidchart link fixed drawio link
Corrected broken URL in databasew2 prepexw2
Improve SQL markup in READMEs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Ruba,
There are two points that you need to rework. I have made them explicit.
Please be aware of your git history. It contains a lot of irrelevant commits. Try to avoid dirty git history next time. git rebase
is your good friend if you want a clean git history.
Feel free to ping me if you have questions!
Week3/Assignmen/transaction.js
Outdated
const reduceBalanceQuery = ` | ||
UPDATE account | ||
SET balance = balance - 1000 | ||
WHERE account_number = 1; | ||
`; | ||
|
||
const addAmountQuery = ` | ||
UPDATE account | ||
SET balance = balance + 1000 | ||
WHERE account_number = 2; | ||
`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In reality you cannot transfer money without enough balance. Hence it makes more sense if you add logic to check balances before transaction.
Week3/Assignmen/club.md
Outdated
. Dinners => dinner_id, dinner_dat | ||
. Venues => venue_code, venue_description | ||
. Foods => food_code, food_descriptio | ||
. Dinner_Venue => dinner_id, venue_cod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's one dinner to many venue code it's needed to use a separate relationship table. Otherwise having a column in dinner table for venue code is fine.
Week3/Assignmen/exercise4/CRUD.js
Outdated
try { | ||
await client.connect(); | ||
const database = client.db("databaseWeek3"); | ||
const collection = database.collection("bob_ross_episodes"); | ||
|
||
const newDocument = { | ||
title: "Mountain View", | ||
elements: ["mountains", "sky", "trees"] | ||
}; | ||
const createResult = await collection.insertOne(newDocument); | ||
console.log(`New document created with the _id: ${createResult.insertedId}`); | ||
|
||
const cursor = collection.find(); | ||
await cursor.forEach(doc => console.dir(doc)); | ||
|
||
const updateQuery = { title: "Mountain View" }; | ||
const update = { $set: { title: "Beautiful Mountain View" } }; | ||
const updateResult = await collection.updateOne(updateQuery, update); | ||
console.log(`${updateResult.modifiedCount} document(s) updated`); | ||
|
||
const deleteQuery = { title: "Beautiful Mountain View" }; | ||
const deleteResult = await collection.deleteOne(deleteQuery); | ||
console.log(`${deleteResult.deletedCount} document(s) deleted`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs rework: you need to write code for the questions in this file.
Week3/Assignmen/exercise3.js
Outdated
function getPopulation(Country, name, code, cb) { | ||
|
||
const query = `SELECT Population FROM ?? WHERE Name = ? and code = ?`; | ||
const values = [Country, name, code]; | ||
|
||
conn.query(query, values, (err, result) => { | ||
if (err) return cb(err); | ||
if (result.length === 0) return cb(new Error("Not found")); | ||
cb(null, result[0].Population); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs rework: I didn't see your answer for question 1 in exercise 3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Ruba,
I didn't see your answer for the question 1 in exercise 3. Please let me know where you put it if you have answered it before.
There's one issue in your mongodb answers. Please check the comment.
Have a nice weekend!
Week3/Assignmen/exercise3.js
Outdated
function getPopulation(Country, name, code, cb) { | ||
const query = `SELECT Population FROM ?? WHERE Name = ? AND code = ?`; | ||
|
||
const query = `SELECT Population FROM ?? WHERE Name = ? and code = ?`; | ||
const values = [Country, name, code]; | ||
conn.query(query, [Country, name, code], function (err, result) { | ||
if (err) { | ||
cb(err); | ||
return; | ||
} | ||
|
||
if (result.length == 0) { | ||
cb(new Error("Not found")); | ||
return; | ||
} | ||
|
||
conn.query(query, values, (err, result) => { | ||
if (err) return cb(err); | ||
if (result.length === 0) return cb(new Error("Not found")); | ||
cb(null, result[0].Population); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to work: maybe I missed something but I still didn't see your answer for the question 1 in exercise 3 about the example value that would take advantage of SQL-injection and ( fetch all the records in the database)?
Week3/Assignmen/exercise4/index.js
Outdated
const updatedBushes = await collection.updateMany( | ||
{ elements: "BUSHES" }, | ||
{ $pull: { elements: "BUSHES" } } | ||
); | ||
console.log(`Ran a command to remove all BUSHES and it updated ${updatedBushes.modifiedCount} episodes`); | ||
|
||
const addBushResult = await collection.updateMany( | ||
{ elements: { $in: ["BUSHES"] } }, | ||
{ $addToSet: { elements: "BUSH" } } | ||
); | ||
console.log(`Ran a command to add 'BUSH' and it updated ${addBushResult.modifiedCount} episodes`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to work: From what I understand, you want to first remove all elements of BUSHES
and then add BUSH
. However, after you remove BUSHES
, how can you find the correct documents in the second step? No elements
contains BUSHES
after deletion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
No description provided.