Skip to content

Conversation

@aleksandrstarshynov
Copy link

No description provided.

Copy link

@RHSebregts RHSebregts left a comment

Choose a reason for hiding this comment

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

Hi,

Once again sorry for taking so long. I'm afraid there is still some work, or at the very least some clarifying to do here. The structure/naming of the files made it a bit harder to work on, and some interesting decisions have been made.
I'd encourage you to experiment with different drivers, database forms and other things, but it might also cause a lack of focus and polish. If you can do a bit of a cleanup this will all be fine, but it makes it a bit harder to get insights into why you made certain choices and what level of understanding you have.
Feel free to reach out!

@@ -0,0 +1,21 @@
const sqlite3 = require('sqlite3').verbose();

Choose a reason for hiding this comment

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

a new week, a new package! Or strictly speaking another DB format. Please, tell me more!
I'm not in love with it yet, I see the return to callback functions over a nice asynchronous approach as a bit of a regression, but I'm ready to be convinced otherwise.

Copy link
Author

Choose a reason for hiding this comment

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

You mean that if we have Promises and async functions already, why I am using SQLite3 and specifically the callback-style API? Good question. The answer is: I do not know. I feel that sometimes curriculum is not up to date and try to find what the most usable staff in the current moment. I like callbacks, we use them a lot in API.

Choose a reason for hiding this comment

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

Let me first say that it is good to be curious and look at what's out there. It's a good skill to have as a developer and it will serve you well in your career. One of the most difficult parts of this curiosity, especially in a field that we're still exploring, is knowing what and why things are done a certain way. And that it can distract from getting down the fundamentals.
In this case, your curiosity killed the cat a bit. SQLite and MySQL are not interchangeable and serve quite different purposes. In this case it's ok, since we are using a small data set, but for bigger projects it will have big limitations. It was also just not the assignment.

Allow me an analogy: Let's say that what HYF is trying to do is teaching you how to cook in the French style. And if you want to be a good cook, you need to know the basics in order to know what to look out for when you start developing your own recipes. There are other cuisines that might be more to our tastes, but knowing a single way of cooking first (French in this case) will allow us to use pick up the other techniques better because we understand the fundamentals. The cuisine itself doesn't matter much here, more the fact that we pick one for now and stick with it.

I agree, MySQL is old and creaky, and I don't care much for it either, but it is still running the world and used at basically every company apart from the hippest of startups. And even those will often have a relational db somewhere, just to make sure people don't go crazy.

Callbacks are amazing, and super fun and powerful, but with database queries (especially when they start to depend on each other) they tend to lead to callback hell, which we try to avoid.

Comment on lines +9 to +11
author_name TEXT,
university TEXT,
date_of_birth TEXT,

Choose a reason for hiding this comment

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

Does this TEXT type guarantee anything about values being null?

Copy link
Author

Choose a reason for hiding this comment

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

oh, gash, my bad. In parallel with assignment I have created local db and code and tried to use, test, etc. And I made all fields as non-requider and expecting text, to make my test easier. Sorry, I totally forget to change it back. For sure we have to use VARCHAR(n) or TEXT, DATE for the date_of_birth and NOT NULL. I will update the assignment

@@ -0,0 +1,42 @@
const sqlite3 = require('sqlite3').verbose();

const db = new sqlite3.Database('example.db');

Choose a reason for hiding this comment

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

example.db?

});

db.run(`
PRAGMA foreign_keys = OFF;

Choose a reason for hiding this comment

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

What does this do?

Copy link
Author

Choose a reason for hiding this comment

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

we work with relational database here. It means that we have under the hood check that we have everything we heeb for the key on the both sides. If we have a key, we check that we have "part" of it in both tables. I guess that by using PRAGMA foreign_keys = OFF we switch-off the check

Choose a reason for hiding this comment

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

Ah, I have never worked with SQLite and just really don't know what this PRAGMA stands for. Normally I would look it up myself, but since we're both here to learn I'd love to know if you can find out what the PRAGMA does.

Comment on lines 18 to 26
CREATE TABLE authors_new (
author_id INTEGER PRIMARY KEY,
author_name TEXT,
university TEXT,
date_of_birth TEXT,
h_index INTEGER,
gender TEXT,
mentor INTEGER,
FOREIGN KEY (mentor) REFERENCES authors(author_id)

Choose a reason for hiding this comment

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

Wait, I thought we already made this table in create_author_table.js? Why are we filling in all it's information again?

Copy link
Author

Choose a reason for hiding this comment

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

Good question. I stuck here during the coding. In Postgres we asielly able to add new column with foreign key ALTER TABLE authors ADD COLUMN mentor INTEGER REFERENCES authors(author_id);
But with SQLite we create a new tablewith the same columns as old one, plus we are including the new column with a foreign key constraint. Then we need to drop existing table and rename the new table. So it replaces the old one and all code that works with the table still able to be linked.
If I found the long way and the way shorted is exist, please show me.

Choose a reason for hiding this comment

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

I refuse to believe that we cannot alter a table in SQLite like we can in MySQL, let's look at this together!

Copy link
Author

Choose a reason for hiding this comment

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


try {
// Выбираем базу данных
await connection.query("USE w2_assignment");

Choose a reason for hiding this comment

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

Coming from the other files, does this collection exist?


// 📌 Запрос 1: Авторы и их менторы
const [authors_mentors] = await connection.query(`
SELECT a.author_name AS Author, m.author_name AS Mentor, a.mentor AS "Mentor ID"

Choose a reason for hiding this comment

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

👍

FROM authors AS a
LEFT JOIN authorPapers AS ap ON a.author_id = ap.author_id
LEFT JOIN research_Papers AS rp ON rp.paper_id = ap.paper_id
ORDER BY a.author_id

Choose a reason for hiding this comment

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

Why would we order on author_id, would users want to do that?

Copy link
Author

Choose a reason for hiding this comment

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

I do not know. It that moment it find this as a good idea. But after your question I see that in real world users will use another column for filtering and ordering. Make no sence in this assignment to order by ID, I agree wth you.

try {
await connection.query("USE w2_assignment");

// 1. Все статьи и количество авторов

Choose a reason for hiding this comment

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

Dit maakt het niet echt makkelijker voor mij om te lezen wat hier staat.

Copy link
Author

Choose a reason for hiding this comment

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

Ik ben het met je eens. Als we internationale regels gebruiken, moet ik Engels gebruiken in de opmerkingen of tips in de code.
I will update tips during the code update, sorry.

JOIN
authorPapers ap ON a.author_id = ap.author_id
WHERE
a.gender = 'Female';

Choose a reason for hiding this comment

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

Since we can add all possible text in this field, will this get us all variations (writing wise) of Female?

Copy link
Author

Choose a reason for hiding this comment

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

You mean that if we have more then one way to write the word in values of the column, by running my code we will get only one type? Make sence. However, I think that better not to give users opportunity to write in, but schoose from the dropdown. In this case we have always only one type, one variation.
From the expirience perspective, is it better everytime to be sure that we code all variation, or we may trast system and specification?

Choose a reason for hiding this comment

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

I like your suggestion, but it makes our database very dependent and coupled to a specific frontend. Let's say we also expose this through an API where someone can arbitrarily type "mAle" of "FEMAle"? I would always try and keep in mind whether or not you want to be case-sensitive or insensitive. So here, I think we can do something with the LIKE keyword to negate that.

@aleksandrstarshynov
Copy link
Author

structure/naming of the files made it a bit harder to work on, and some interesting decisions have been made.
I'd encourage you to experiment with different drivers, database forms and other things, but it might also cause a lack of focus and polish. If you can do a bit of a cleanup this will all be fine, but it makes it a bit harder to get insights into why you made certain choices and what level of understanding you have.
Feel free to reach out!

I think that I have two problems in this module. First is a lack of time, we got mysql, next week nosql... I have not mix but the real mash in my head. And the second issue is that I am not able to remember the sql sintax. Evrry time i have to google or ask chat. Maybe because of this I try not to play with different approaches or structures for the databases. PostrgeSQL and relational databases is more interesting for me. However, in my side project I set up and usinf both.

@RHSebregts
Copy link

I think that I have two problems in this module. First is a lack of time, we got mysql, next week nosql... I have not mix but the real mash in my head. And the second issue is that I am not able to remember the sql sintax. Evrry time i have to google or ask chat. Maybe because of this I try not to play with different approaches or structures for the databases. PostrgeSQL and relational databases is more interesting for me. However, in my side project I set up and usinf both.

Once again, I admire that you are trying to do a lot, but I think you can help yourself by focussing a bit more on deepening your knowledge as opposed to widening it too much now. I feel that, by now, you should start to get to a stage where you have those SQL queries in your toolbelt. If not, you should first get that down, since they are really fundamental, also for Postgres and other DBs. But also, having to google them is natural and I still need to do that with anything beyond the basics as well.

Also you say Postgres and relational databases are more interesting to you, but it seems to me that MySQL is pretty much the OG relational database.

@aleksandrstarshynov
Copy link
Author

I think that I have two problems in this module. First is a lack of time, we got mysql, next week nosql... I have not mix but the real mash in my head. And the second issue is that I am not able to remember the sql sintax. Evrry time i have to google or ask chat. Maybe because of this I try not to play with different approaches or structures for the databases. PostrgeSQL and relational databases is more interesting for me. However, in my side project I set up and usinf both.

Once again, I admire that you are trying to do a lot, but I think you can help yourself by focussing a bit more on deepening your knowledge as opposed to widening it too much now. I feel that, by now, you should start to get to a stage where you have those SQL queries in your toolbelt. If not, you should first get that down, since they are really fundamental, also for Postgres and other DBs. But also, having to google them is natural and I still need to do that with anything beyond the basics as well.

Also you say Postgres and relational databases are more interesting to you, but it seems to me that MySQL is pretty much the OG relational database.

@RHSebregts I see what i are mean. Just to be sure that I am following you in expected way, should I finish with SQLite or in order to do assignment better I need to re-do it with PostgreSQL? I feel that in this case Postgress is more teaching method.

@RHSebregts
Copy link

I think that I have two problems in this module. First is a lack of time, we got mysql, next week nosql... I have not mix but the real mash in my head. And the second issue is that I am not able to remember the sql sintax. Evrry time i have to google or ask chat. Maybe because of this I try not to play with different approaches or structures for the databases. PostrgeSQL and relational databases is more interesting for me. However, in my side project I set up and usinf both.

Once again, I admire that you are trying to do a lot, but I think you can help yourself by focussing a bit more on deepening your knowledge as opposed to widening it too much now. I feel that, by now, you should start to get to a stage where you have those SQL queries in your toolbelt. If not, you should first get that down, since they are really fundamental, also for Postgres and other DBs. But also, having to google them is natural and I still need to do that with anything beyond the basics as well.
Also you say Postgres and relational databases are more interesting to you, but it seems to me that MySQL is pretty much the OG relational database.

@RHSebregts I see what i are mean. Just to be sure that I am following you in expected way, should I finish with SQLite or in order to do assignment better I need to re-do it with PostgreSQL? I feel that in this case Postgress is more teaching method.

Let's finish this in MySQL!

GROUP BY
rp.paper_id;
`);
console.log("\n1️⃣ Papers and number of authors:");

Choose a reason for hiding this comment

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

Using emojis is completely fine! Sorry for giving you the impression you should've changed that!

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.

2 participants