0
0
NestJSframework~5 mins

Prisma Client usage in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is Prisma Client in the context of NestJS?
Prisma Client is an auto-generated database client that lets you easily read and write data in your database using simple and type-safe JavaScript or TypeScript code within a NestJS application.
Click to reveal answer
beginner
How do you typically inject Prisma Client into a NestJS service?
You create a PrismaService that extends PrismaClient and mark it as injectable. Then you inject PrismaService into other services via constructor injection to access database methods.
Click to reveal answer
beginner
What method would you use to find a single record by its unique ID using Prisma Client?
You use the findUnique method with a where clause specifying the unique ID, for example: prisma.user.findUnique({ where: { id: 1 } }).
Click to reveal answer
intermediate
Why is Prisma Client considered type-safe?
Because Prisma Client generates TypeScript types based on your database schema, it helps catch errors early by providing autocomplete and compile-time checks when you write queries.
Click to reveal answer
intermediate
How do you handle database connection cleanup in Prisma Client within a NestJS app?
You override the onModuleDestroy lifecycle hook in your PrismaService to call this.$disconnect(), ensuring the database connection closes properly when the app stops.
Click to reveal answer
Which method in Prisma Client is used to create a new record?
Acreate()
Binsert()
Cadd()
Dnew()
How do you access Prisma Client inside a NestJS service?
ABy injecting a PrismaService that extends PrismaClient
BBy importing PrismaClient directly in every service
CBy calling PrismaClient as a global variable
DBy using PrismaClient without any import
What does the findUnique() method require to find a record?
AA filter object with any field
BAn array of IDs
CA where clause with a unique field
DNo parameters
Which lifecycle hook is used in NestJS to disconnect Prisma Client on app shutdown?
AonModuleInit
BafterApplicationShutdown
CbeforeApplicationShutdown
DonModuleDestroy
Why is Prisma Client preferred over raw SQL queries in NestJS?
AIt is faster than SQL
BIt provides type safety and easier syntax
CIt does not require a database
DIt automatically creates database tables
Explain how you set up and use Prisma Client in a NestJS service.
Think about dependency injection and how PrismaClient methods are accessed.
You got /4 concepts.
    Describe how Prisma Client ensures type safety and why it matters.
    Consider how TypeScript helps prevent mistakes.
    You got /4 concepts.