The tutorial demonstrates migrating a Nest.js reservation service from MongoDB to PostgreSQL using Prisma. It covers creating the Prisma service, updating database modules, refactoring DTOs into interfaces, adjusting controller methods for proper type handling, and updating environment configurations for Docker networking.
Length 14:14
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #prisma #typescript #nest.js #postgresql #refactoring #backend #database #programming #docker
0:00 All right, so our first step in actually integrating 0:02 Prisma into 0:03 Reservations is to create a service that's going to act 0:07 as the entry point for any other calls to Prisma 0:11 and to our database. So this is gonna be very similar to how we've 0:15 already set up an abstract repository for MongoDB, 0:19 which we were able to swap out for TypeORM very 0:23 easily. Prisma is not gonna be the same because of 0:27 how 0:27 it actually uses the Prisma Client type generation. 0:31 We're not gonna utilize the abstract repository. 0:33 Instead, we're gonna use the Prisma Client 0:36 directly, and this is 0:37 because Prisma is actually acting as the abstract 0:41 repository itself now. It's gonna be encapsulating 0:45 all of the calls we make to the database in a consistent 0:49 API, and we can swap out this database 0:52 provider here with any other provider at runtime. 0:56 And essentially, this is going to be mimicking what our abstract 0:59 repository 1:00 previously gave us by encapsulating all of this in a 1:04 common set of library API calls. So let's go ahead and 1:07 create a new Prisma service 1:11 inside of the Reservations source folder, 1:15 and this will be an injectable class that we're gonna inject wherever we need 1:19 to interact with the database. 1:22 And so we'll export Prisma service. 1:25 Now, the key bit to get access to our 1:26 underlying schema type 1:28 generation is to now extend Prisma 1:32 Client, and we go ahead and provide an import to Prisma 1:36 Client. 1:37 Now, this needs to be a custom import from 1:40 .prisma/client. Now, remember, this 1:44 is the output path that we specified earlier 1:47 inside of our schema.prisma to this 1:51 .prisma/client, and this is gonna make sure our code looks for the 1:54 local 1:55 node modules folder and not at the root of our project. 1:58 So this is gonna give us access to all of the underlying types that Prisma
The rest of the transcript is for members.
Sign in