const{ prisma }=require('./generated/prisma-client')// A `main` function so that we can use async/awaitasyncfunctionmain(){// Create a new user called `Alice`const newUser =await prisma.createUser({ name:'Alice'})
console.log(`Created new user: ${newUser.name} (ID: ${newUser.id})`)// Read all users from the database and print them to the consoleconst allUsers =await prisma.users()
console.log(allUsers)}main().catch(e => console.error(e))

Copy

Execute the script with the following command:

node index.js

Copy

Whenever you run this script with that command, a new user record is created in the database (because of the call to createUser).

Feel free to play around with the Prisma client API and try out some of the following operations by adding the following code snippets to the file (at the end of the main function) and re-executing the script:

Fetch single user

Filter user list

Update a user's name

Delete user

const user =await prisma
.user({ id:'__USER_ID__'})

Copy

In some snippets, you need to replace the __USER__ID__ placeholder with the ID of an actual user.

Great work! 👏 Move on to learn how you can change your datamodel and (re-)generate your Prisma client.