Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the database client in a Next.js server component.
NextJS
import [1] from '@/lib/dbClient';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing React instead of the database client
Using useState which is a React hook
Trying to import fetch as the database client
✗ Incorrect
We import the database client to access the database in Next.js server components.
2fill in blank
mediumComplete the code to fetch all users from the database using the client.
NextJS
const users = await dbClient.[1].findMany(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using create instead of findMany
Using delete or update which modify data
✗ Incorrect
The findMany method fetches multiple records from the database.
3fill in blank
hardFix the error in the code to correctly fetch a user by ID.
NextJS
const user = await dbClient.user.findUnique({ where: { id: [1] } }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not match the field
Using dot notation incorrectly
✗ Incorrect
The where clause expects the exact field name id with the value to match.
4fill in blank
hardFill both blanks to create a new user with name and email.
NextJS
await dbClient.user.create({ data: { name: [1], email: [2] } }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of string literals
Missing quotes around strings
✗ Incorrect
We provide string values for name and email inside the data object.
5fill in blank
hardFill all three blanks to update a user's email by ID.
NextJS
await dbClient.user.update({ where: { id: [1] }, data: { email: [2] }, select: { [3]: true } }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names
Not quoting the new email string
Selecting wrong fields
✗ Incorrect
We specify the user ID, new email string, and select the email field to return.