Skip to content

Commit 208c0f6

Browse files
committed
update Prisma recipe to Prisma 2
1 parent 4211bbd commit 208c0f6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

content/recipes/prisma.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Prisma is used as an alternative to writing plain SQL, or using another database
66

77
While Prisma is a _toolkit_ that contains _multiple_ tools, the focus of this guide will be on using [Prisma Client](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client). Prisma Client is an auto-generated and type-safe query builder that lets you read and write data in your database.
88

9-
> **Note** If you want to get a quick overview of how Prisma works, you can follow the [Quickstart](https://www.prisma.io/docs/getting-started/quickstart) or read the [Introduction](https://www.prisma.io/docs/understand-prisma/introduction) in the [documentation](https://www.prisma.io/docs/).
9+
> **Note** If you want to get a quick overview of how Prisma works, you can follow the [Quickstart](https://www.prisma.io/docs/getting-started/quickstart) or read the [Introduction](https://www.prisma.io/docs/understand-prisma/introduction) in the [documentation](https://www.prisma.io/docs/). There also is a great [`nestjs-prisma-starter`](https://github.com/fivethree-team/nestjs-prisma-starter) project available if you want to get started using NestJS with Prisma in production.
1010
1111
#### Getting started
1212

@@ -260,14 +260,14 @@ Note that this command automatically invokes the `prisma generate` command for y
260260

261261
> **Note** The `prisma generate` command reads your Prisma schema and updates the generated Prisma Client library inside `node_modules/@prisma/client`.
262262
263+
263264
##### 7. Use Prisma Client in your NestJS services
264265

265266
You're now able to send database queries with Prisma Client! If you want to learn about the possible queries with Prisma Client, check out the [API documentation](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/crud).
266267

267-
268268
When setting up your NestJS application, you'll want to abstract away the Prisma Client API for database queries within a _service_. To get started, you can create a new `PrismaService` that takes care of instantiating `PrismaClient` and connecting to your database.
269269

270-
Inside the `src` dirtectory, create a new file called `prisma.service.ts` and add the following code to it:
270+
Inside the `src` directory, create a new file called `prisma.service.ts` and add the following code to it:
271271

272272
```typescript
273273
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
@@ -291,7 +291,7 @@ export class PrismaService extends PrismaClient
291291

292292
Next, you can write services that you can use to make database calls for the `User` and `Post` models from your Prisma schema.
293293

294-
Still inside the `src` dirtectory, create a new file called `user.service.ts` and add the following code to it:
294+
Still inside the `src` directory, create a new file called `user.service.ts` and add the following code to it:
295295

296296
```typescript
297297
import { Injectable } from '@nestjs/common';
@@ -361,7 +361,8 @@ Notice how you're using Prisma Client's generated types to ensure that the metho
361361

362362
Now do the same for the `Post` model.
363363

364-
Still inside the `src` dirtectory, create a new file called `post.service.ts` and add the following code to it:
364+
365+
Still inside the `src` directory, create a new file called `post.service.ts` and add the following code to it:
365366

366367
```typescript
367368
import { Injectable } from '@nestjs/common';
@@ -522,13 +523,14 @@ export class AppController {
522523
}
523524
```
524525

525-
This implements the following routes:
526+
This controller implements the following routes:
527+
526528

527529
###### `GET`
528530

529531
- `/post/:id`: Fetch a single post by its `id`
530532
- `/feed`: Fetch all _published_ posts
531-
- `/filterPosts?searchString={searchString}`: Filter posts by `title` or `content`
533+
- `/filterPosts/:searchString`: Filter posts by `title` or `content`
532534

533535
###### `POST`
534536

@@ -550,6 +552,7 @@ This implements the following routes:
550552

551553
- `/post/:id`: Delete a post by its `id`
552554

555+
553556
#### Summary
554557

555558
In this guide, you learned how to implement a use NestJS together with Prisma to implement a REST API. The controller who implements the routes of the API is calling a `PrismaService` which in turn uses Prisma Client to send queries to a database to fulfill the data needs of incoming requests.

0 commit comments

Comments
 (0)