Challenge - 5 Problems
Prisma CRUD Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Prisma create operation?
Given the following NestJS Prisma service code, what will be the output when creating a new user with name 'Alice' and email 'alice@example.com'?
NestJS
async createUser() { const user = await this.prisma.user.create({ data: { name: 'Alice', email: 'alice@example.com' } }); return user; }
Attempts:
2 left
💡 Hint
Prisma automatically generates the 'id' field if it is set as an auto-increment primary key.
✗ Incorrect
The create method returns the full created record including the auto-generated id. The data object only needs the fields to set; Prisma adds the id.
❓ state_output
intermediate2:00remaining
What is the result of this Prisma update operation?
Consider this update method in a NestJS Prisma service. What will be the returned value after updating the user with id 5 to have name 'Bob'?
NestJS
async updateUser() { const updatedUser = await this.prisma.user.update({ where: { id: 5 }, data: { name: 'Bob' } }); return updatedUser; }
Attempts:
2 left
💡 Hint
Prisma throws an error if you try to update a record that does not exist.
✗ Incorrect
The update method throws a PrismaClientKnownRequestError if no record matches the where condition.
🔧 Debug
advanced2:00remaining
Why does this Prisma delete operation fail?
This NestJS Prisma service method tries to delete a user by id but fails with a runtime error. What is the cause?
NestJS
async deleteUser(id: number) { await this.prisma.user.delete({ where: { userId: id } }); }
Attempts:
2 left
💡 Hint
Check the exact field names in your Prisma schema for the User model.
✗ Incorrect
The where clause must use the exact unique field name defined in the Prisma schema. If the primary key is id, using userId causes an error.
📝 Syntax
advanced2:00remaining
Which option correctly fetches all users with Prisma in NestJS?
Select the correct Prisma query to fetch all users from the database.
Attempts:
2 left
💡 Hint
Check the Prisma Client API for fetching multiple records.
✗ Incorrect
The correct method to fetch multiple records is findMany(). Other methods do not exist in Prisma Client.
🧠 Conceptual
expert2:00remaining
What happens if you call Prisma update with no matching record?
In NestJS Prisma, what is the behavior when you call
prisma.user.update with a where clause that matches no records?Attempts:
2 left
💡 Hint
Consider how Prisma handles updates on non-existent records.
✗ Incorrect
The update method requires an existing record. If none matches, Prisma throws a PrismaClientKnownRequestError.