Skip to content
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

Open
wants to merge 397 commits into
base: main
Choose a base branch
from

Conversation

RubaMansour
Copy link

No description provided.

unmeshvrije and others added 30 commits March 18, 2020 17:20
delete unnecessary info and typos in homework
…ce of timing between a column having an index and a column not having one
@yunchen4 yunchen4 self-assigned this Jan 17, 2025
Copy link

@yunchen4 yunchen4 left a 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!

Comment on lines 13 to 23
const reduceBalanceQuery = `
UPDATE account
SET balance = balance - 1000
WHERE account_number = 1;
`;

const addAmountQuery = `
UPDATE account
SET balance = balance + 1000
WHERE account_number = 2;
`;

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.

. Dinners => dinner_id, dinner_dat
. Venues => venue_code, venue_description
. Foods => food_code, food_descriptio
. Dinner_Venue => dinner_id, venue_cod

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.

Comment on lines 13 to 35
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`);

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.

Comment on lines 1 to 11
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);
});
}

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?

Copy link

@yunchen4 yunchen4 left a 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!

Comment on lines 1 to 17
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);
});
}

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)?

Comment on lines 69 to 80
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`);
}

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.

Copy link

@yunchen4 yunchen4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.