Challenge - 5 Problems
ORM Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
What does ORM stand for and what is its main purpose?
Choose the correct definition and purpose of ORM in Node.js frameworks like Sequelize and Prisma.
Attempts:
2 left
💡 Hint
Think about how code objects relate to database tables.
✗ Incorrect
ORM stands for Object-Relational Mapping. It helps developers work with databases by mapping code objects to database tables, making database operations easier and more intuitive.
❓ component_behavior
intermediate2:00remaining
What will be the output of this Prisma query?
Given this Prisma client code, what will be the value of 'users' after execution?
Node.js
const users = await prisma.user.findMany({ where: { age: { gt: 18 } } });
Attempts:
2 left
💡 Hint
Look at the 'findMany' method and the 'where' filter.
✗ Incorrect
The findMany method returns an array of all user records matching the condition. Here, it returns users with age greater than 18.
📝 Syntax
advanced2:00remaining
Which Sequelize model definition is syntactically correct?
Select the option that correctly defines a Sequelize model for a 'Product' with 'name' as string and 'price' as float.
Attempts:
2 left
💡 Hint
Remember to use DataTypes for field types in Sequelize.
✗ Incorrect
Sequelize requires using DataTypes to specify field types when defining models. Option A correctly uses DataTypes.STRING and DataTypes.FLOAT.
🔧 Debug
advanced2:00remaining
Why does this Prisma query throw an error?
Consider this Prisma query code snippet. Why does it throw a runtime error?
const user = await prisma.user.findUnique({ where: { email: 'test@example.com' } });
console.log(user.name.toUpperCase());
Attempts:
2 left
💡 Hint
Think about what happens if no user matches the email.
✗ Incorrect
If no user matches the email, findUnique returns null. Trying to access name on null causes a runtime error.
❓ state_output
expert3:00remaining
What is the final state of the database after this Sequelize transaction?
Given this Sequelize transaction code, what will be the final state of the 'Orders' table if an error occurs during the second create call?
const t = await sequelize.transaction();
try {
await Order.create({ item: 'Book', quantity: 1 }, { transaction: t });
await Order.create({ item: null, quantity: 2 }, { transaction: t }); // item cannot be null
await t.commit();
} catch (error) {
await t.rollback();
}
What happens to the 'Orders' table?
Attempts:
2 left
💡 Hint
Remember how transactions work when an error occurs.
✗ Incorrect
Sequelize transactions ensure all operations succeed or none do. If an error occurs, the transaction rolls back, so no changes are saved.