How to implement database first approach in Nest JS

622 Views Asked by At

I have three schemas(User, Account, Contact) these three schemas used to created a model and generate the migration files also Next, this migration file migrate the PostgreSQL Database this part successfully completed using Nest JS.

Next, Manually I created one table and added few columns in the table. In this table(model) I need automatically integrate in our Nest JS CODE is it possible?

So, I google it how to achieve this scenario this given one solution schema first approach.

In Nest JS used one Library that is GraphQL this library used to achieve schema first approach. I tried this approach but I could not get the database model in our code.

Anyone tell me how to achieve this scenario

1

There are 1 best solutions below

0
On

/Combining NestJS and Prisma provides a new level of type-safety that is impossible to achieve with any other ORM from the Node.js & TypeScript ecosystem. This example demonstrates how to use Prisma Client./

import { Injectable, OnModuleInit, INestApplication } from '@nestjs/common'
import { PrismaClient } from '@prisma/client'

@Injectable()
export class PrismaService extends PrismaClient
implements OnModuleInit {

async onModuleInit() {
 await this.$connect();
}

async enableShutdownHooks(app: INestApplication) {
    this.$on('beforeExit', async () => {
     await app.close();
    });    
  }
}