Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new record using Sequelize.
Express
const newUser = await User.[1]({ name: 'Alice', email: 'alice@example.com' });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using findAll instead of create will only fetch data, not add new data.
Using update or destroy will modify or delete data, not create.
✗ Incorrect
The create method is used to add a new record to the database in Sequelize.
2fill in blank
mediumComplete the code to find all users with Sequelize.
Express
const users = await User.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using create will add data, not fetch it.
Using update or destroy will change or delete data, not fetch.
✗ Incorrect
The findAll method retrieves all records from the database table.
3fill in blank
hardFix the error in the update operation code.
Express
await User.[1]({ name: 'Bob' }, { where: { id: 5 } });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using create will add new data instead of updating.
Using findAll fetches data but does not update.
✗ Incorrect
The update method updates existing records matching the where condition.
4fill in blank
hardFill both blanks to delete a user by id using Sequelize.
Express
await User.[1]({ where: { id: [2] } });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using update or create will not delete records.
Passing a wrong id will delete the wrong user or none.
✗ Incorrect
The destroy method deletes records matching the where condition. Here, the user with id 5 is deleted.
5fill in blank
hardFill all three blanks to find a user by primary key and update their email.
Express
const user = await User.[1](10); if (user) { await user.[2]({ email: 'newemail@example.com' }); await user.[3](); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using destroy will delete the user instead of updating.
Not calling save after update may not persist changes.
✗ Incorrect
findByPk finds a record by its primary key. Then update changes the email field. Finally, save saves the changes to the database.