Skip to content

Conversation

@YaroslavKazeev
Copy link

No description provided.

@yunchen4 yunchen4 self-assigned this Sep 12, 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 Yaroslav,
LGTM. I left some suggestions for better code quality and readability. If you have any questions, please let me know.

Comment on lines +1 to +7
export const accounts = [
{ account_number: 101, balance: 5000 },
{ account_number: 102, balance: 12000 },
{ account_number: 103, balance: 7500 },
{ account_number: 104, balance: 3000 },
{ account_number: 105, balance: 9500 },
];

Choose a reason for hiding this comment

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

Suggestion: Same suggestion as week 2, better to use JSON file for pure data. You don't have to change your code but it is better to know.

async function createTables(client) {
const CREATE_ACCOUNT_TABLE = `
CREATE TABLE IF NOT EXISTS account (
account_number SMALLINT PRIMARY KEY,

Choose a reason for hiding this comment

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

If the bank is really small using SMALLINT as PK makes sense. It is not common to use a small type for PK.

Comment on lines +41 to +42
} catch (error) {
console.error("Error seeding database:", error);

Choose a reason for hiding this comment

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

Suggestion: although client.end() will also roll back the changes in case of errors, I will recommend to add await client.query("ROLLBACK") in the catch block to clearly state a rollback operation will be done. It has several advantages:

  • When I read the code, I know in case of errors the changes will be rolled back instead of guessing whether rollback will be done.
  • client.end() will roll back changes in PostgreSQL, but not necessarily in other types of databases or in other versions. We shouldn't rely on this kind of implicit operations.

Copy link
Author

Choose a reason for hiding this comment

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

I would like to save a couple of code lines and rely on the behavior of the Postgres database management system, which should be known to the developer's team. On top of that, I do not expect it to be changed to let's say, MySQL, which will require the rewrite of many functions, where a transaction block is just one of them.
Although I understand that you have more experience, your argument is not convincing for now. This approach creates safeguards twice: in the RDBMS and in the app's code.

Comment on lines +109 to +111
const bobRossCollection = await client
.db("databaseWeek3")
.collection("bob_ross_episodes");

Choose a reason for hiding this comment

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

Suggestion: these lines for client initialization appears several times in the file. You can extract it as a function which returns the client. And if a string repeats several times in a file (in case you don't extract it as a function), it is better to have a constant for it, so you can avoid typos.

Comment on lines +16 to +17
const donator_account_number = 101;
const receiver_account_number = 102;

Choose a reason for hiding this comment

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

Suggestion: in real life situation it is better to check whether the account exists and the balance is enough before doing actual transactions.

Copy link
Author

Choose a reason for hiding this comment

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

I disagree once again here. Limitations should be enforced in the DB, for example, allowing the balance only a positive integer. Then, we can rely on the RDBMS to throw an error if some of the transactional statements can not be executed and abort the whole transaction. No check inside the code is needed.

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