Skip to content

Commit 6ab6409

Browse files
author
Mitchell Amihod
committed
docs: clean up example code
I think this is better than my original - that way all the code is in the prismaService Open to other suggestions
1 parent 9f3cd4a commit 6ab6409

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

content/recipes/prisma.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,16 @@ export class PrismaService extends PrismaClient
257257
async onModuleInit() {
258258
await this.$connect();
259259
}
260+
261+
async enableShutdownHooks(app) {
262+
this.$on('beforeExit', async () => {
263+
await app.close();
264+
});
265+
}
260266
}
261267
```
262268

263-
> info **Note** The `onModuleInit` is optional - if you leave it out, Prisma will connect lazily on first call to db. We don't bother with `onModuleDestroy`, since Prisma has its own shutdown hooks where it will destroy the connection.
269+
> info **Note** The `onModuleInit` is optional - if you leave it out, Prisma will connect lazily on first call to db. We don't bother with `onModuleDestroy`, since Prisma has its own shutdown hooks where it will destroy the connection. For more info on `enableShutdownHooks`, please see [Issues with `enableShutdownHooks`](#issues-with-enableShutdownHooks)
264270
265271
Next, you can write services that you can use to make database calls for the `User` and `Post` models from your Prisma schema.
266272

@@ -527,11 +533,7 @@ import { PrismaService } from './services/prisma/prisma.service';
527533
bootstrap() {
528534
...
529535
const prismaService: PrismaService = app.get(PrismaService);
530-
531-
prismaService.$on('beforeExit', async () => {
532-
logger.log('Prisma before exit...');
533-
await app.close();
534-
});
536+
prismaService.enableShutdownHooks(app)
535537
...
536538
}
537539
```

0 commit comments

Comments
 (0)