Database Connection


Prisma Supabase Demo

We are using Prisma as ORM and postgresql as database.
Folders And Files

You can add or replace existing models in prisma.schema file

       
                
model product {
  id           String   @id @default(auto()) @map("_id") @db.ObjectId 
  name         String
  customer     String
  quantity     String
  status       String
  price        String
  imageUrl     String?
  createDate   DateTime @default(now())
  updateDate   DateTime @updatedAt
}
               
               
               

Steps for Creating Postgresql table in Supabase

  • Go to “https://supabase.com/
  • click on "Sign Up" or "Log In" and complete the process.
  • On the dashboard, click on the "New Project" button.
  • After Display popup menu, Enter Project name, Select Country. Setup database password and remember it.
  • After setting up click on the connect button to see your database url. Scroll a little bit down , you will see a transaction pooler . Just copy it and save as Database url in your .env file.
  • Create a new env variable "DIRECT_URL" and grab the value of session pooler from last screen of the supabase.
  • Create a new connection string in prisma named "DIRECT_URL" and get the value from .env
  • Create new model in schema.prisma file or have the existing one after that run "npx prisma db push" to push your model to the postgresql database of supabase.
  • Now , you can check the table-editor and your brand new table is created.You can do any sort of crud operation on the table
  • supabase
  • supabase

Prisma Mongodb-Sqlite Demo

We are using Prisma as ORM and mongodb or sqlite as database.
Folders And Files

You can add or replace existing models in prisma.schema file

       
                
model product {
  id           String   @id @default(auto()) @map("_id") @db.ObjectId 
  name         String
  customer     String
  quantity     String
  status       String
  price        String
  imageUrl     String?
  createDate   DateTime @default(now())
  updateDate   DateTime @updatedAt
}