<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tushar Patil</title>
    <description>The latest articles on DEV Community by Tushar Patil (@tush03).</description>
    <link>https://dev.to/tush03</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2974209%2F3d48ac47-e398-4247-b0c6-8d47e0097c6c.jpeg</url>
      <title>DEV Community: Tushar Patil</title>
      <link>https://dev.to/tush03</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tush03"/>
    <language>en</language>
    <item>
      <title>Handle Many to Many Relations in PostgreSQL using Prisma ORM</title>
      <dc:creator>Tushar Patil</dc:creator>
      <pubDate>Tue, 17 Jun 2025 15:34:09 +0000</pubDate>
      <link>https://dev.to/tush03/handle-many-to-many-relations-in-postgresql-using-prisma-orm-11cn</link>
      <guid>https://dev.to/tush03/handle-many-to-many-relations-in-postgresql-using-prisma-orm-11cn</guid>
      <description>&lt;p&gt;Handling many-to-many relationships in PostgreSQL using Prisma is straightforward and efficient. Prisma can manage both implicit and explicit many-to-many relations.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Implicit Many-to-Many Relation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model User {
  id       Int      @id @default(autoincrement())
  name     String
  projects Project[] // Many-to-many relation
}

model Project {
  id    Int    @id @default(autoincrement())
  title String
  users User[] // Many-to-many relation
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By declaring each side as a list of the other, Prisma knows to spin up a hidden join table for you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Generated SQL Migration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you run prisma migrate dev, Prisma will produce SQL akin to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- 1. Create the two main tables
CREATE TABLE "User" (
  "id"   SERIAL PRIMARY KEY,
  "name" TEXT   NOT NULL
);

CREATE TABLE "Project" (
  "id"    SERIAL PRIMARY KEY,
  "title" TEXT    NOT NULL
);

-- 2. Create the hidden join table
CREATE TABLE "_UserToProject" (
  "A" INTEGER NOT NULL,
  "B" INTEGER NOT NULL,

  PRIMARY KEY ("A","B"),

  FOREIGN KEY ("A") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY ("B") REFERENCES "Project"("id") ON DELETE CASCADE ON UPDATE CASCADE
);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key points:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The join table is named by alphabetically sorted model names with an underscore prefix: _To.&lt;/p&gt;

&lt;p&gt;Columns are auto‑named "A"/"B"; you never interact with them directly in Prisma Client.&lt;/p&gt;

&lt;p&gt;ON DELETE CASCADE ensures that if a User (or Project) is deleted, all linking rows vanish automatically.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Example 2&lt;/strong&gt;&lt;br&gt;
Here you can see many to many relation in between User and Team,&lt;br&gt;
Team and Project. the joining table for this schema will be created by prisma automatically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model User {
    id       String    @id @default(cuid())
    email    String    @unique
    username String    @unique
    password String
    projects Project[]
    teams    Team[]
}

model Project {
    id        String @id @default(cuid())
    name      String
    creatorId String @map("creator_id")
    creator   User   @relation(fields: [creatorId], references: [id])

    teams Team[]
}

model Team {
    id        String    @id @default(cuid())
    name      String?
    creatorId String    @map("creator_id")
    users     User[]
    projects  Project[]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;implicit handling of many to many relations in prisma is more easier than manually creating a joining table.&lt;br&gt;
but it lacks in flexibility, like in above example user and team have many to many relation, we can not add more field describing additional information about this relation like role of the user in related team.&lt;/p&gt;


&lt;h2&gt;
  
  
  2.Explicit Many to Many Relations
&lt;/h2&gt;

&lt;p&gt;In Explicit Many to Many Relations you have to manually create a join table for tow models.&lt;br&gt;
in this example i created two join tables UserTeam and ProjectTeam.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model User {
    id       String     @id @default(cuid())
    email    String     @unique
    username String     @unique
    password String
    projects Project[]
    teams    UserTeam[]
}

model Project {
    id        String @id @default(cuid())
    name      String
    creatorId String @map("creator_id")
    creator   User   @relation(fields: [creatorId], references: [id])

    teams ProjectTeam[]
}

model Team {
    id        String        @id @default(cuid())
    name      String?
    creatorId String        @map("creator_id")
    users     UserTeam[]
    projects  ProjectTeam[]
}

model UserTeam {
    id     String @id @default(cuid())
    teamId String
    userId String
    team   Team   @relation(fields: [teamId], references: id)
    user   User   @relation(fields: [userId], references: id)
}

model ProjectTeam {
    id      String  @id @default(cuid())
    teamId  String
    userId  String
    team    Team    @relation(fields: [teamId], references: id)
    Project Project @relation(fields: [userId], references: id)
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this manual implementation for joining tables add more flexibility in defining schema, since we can add more fields in join table that does not possible with implicit relations.&lt;/p&gt;

&lt;p&gt;example we can add &lt;strong&gt;role&lt;/strong&gt; for the user in team&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model UserTeam {
    id     String @id @default(cuid())
    teamId String
    userId String
    role   String

    team   Team   @relation(fields: [teamId], references: id)
    user   User   @relation(fields: [userId], references: id)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  💡Conclusion:
&lt;/h2&gt;

&lt;p&gt;choosing between implicit and explicit relational handling is depend upon you project requirement. if you require simpler many to many link between two models or don't need extra data on relation itself then you should go with implicit handling.&lt;br&gt;
if your project require flexibility in schema , to add more data on relation itself, you should try creating a joining table explicitly to handle many to many relation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reference:
&lt;/h3&gt;

&lt;p&gt;Prisma Documentation: &lt;a href="https://www.prisma.io/docs/orm/prisma-schema/data-model/relations/many-to-many-relations" rel="noopener noreferrer"&gt;https://www.prisma.io/docs/orm/prisma-schema/data-model/relations/many-to-many-relations&lt;/a&gt;&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>prisma</category>
      <category>relations</category>
      <category>manytomany</category>
    </item>
    <item>
      <title>🚀 Set Up PostgreSQL with pgAdmin Using Docker (Step-by-Step Guide)</title>
      <dc:creator>Tushar Patil</dc:creator>
      <pubDate>Mon, 19 May 2025 18:17:40 +0000</pubDate>
      <link>https://dev.to/tush03/set-up-postgresql-with-pgadmin-using-docker-step-by-step-guide-240j</link>
      <guid>https://dev.to/tush03/set-up-postgresql-with-pgadmin-using-docker-step-by-step-guide-240j</guid>
      <description>&lt;h3&gt;
  
  
  🚀 Introduction
&lt;/h3&gt;

&lt;p&gt;Managing PostgreSQL databases becomes much easier with pgAdmin, a powerful browser-based GUI. In this guide, you'll learn how to spin up both PostgreSQL and pgAdmin using Docker — no manual installation required!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📝 Note&lt;/strong&gt;&lt;br&gt;
Setting up PostgreSQL and pgAdmin using individual docker run commands is a valid approach, but it requires running multiple commands manually.&lt;/p&gt;

&lt;p&gt;If you prefer using individual Docker commands, follow the steps below.&lt;br&gt;
If you want a cleaner setup, skip directly to the Docker Compose section and run everything with a single command.&lt;/p&gt;


&lt;h3&gt;
  
  
  🛠️ Prerequisites
&lt;/h3&gt;

&lt;p&gt;Make sure the following are installed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ &lt;a href="https://www.docker.com/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;✅ &lt;a href=""&gt;Docker Compose&lt;/a&gt;  (optional)&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  Step 1: Pull PostgreSQL Docker Image
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker pull postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Run PostgreSQL Container
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--name&lt;/span&gt; my-postgres &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_USER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;admin &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;secret &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_DB&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mydb &lt;span class="nt"&gt;-p&lt;/span&gt; 5432:5432 &lt;span class="nt"&gt;-d&lt;/span&gt; postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;🔍 This sets up a PostgreSQL container with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Username: admin&lt;/li&gt;
&lt;li&gt;Password: secret&lt;/li&gt;
&lt;li&gt;Database name: mydb&lt;/li&gt;
&lt;li&gt;Port: Exposes DB on localhost:5432&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  Step 3: Pull pgAdmin Docker Image
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker pull dpage/pgadmin4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Run pgAdmin container
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run --name pgadmin-container \
  -e PGADMIN_DEFAULT_EMAIL=admin@local.com \
  -e PGADMIN_DEFAULT_PASSWORD=admin123 \
  -p 5050:80 \
  -d dpage/pgadmin4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;-Email: &lt;a href="mailto:admin@local.com"&gt;admin@local.com&lt;/a&gt;&lt;br&gt;
-Password: admin123&lt;br&gt;
-port : -p 5050&lt;br&gt;
-image name(you also can use image id) : -d dpage/pgadmin4&lt;/p&gt;

&lt;p&gt;This Starts pgAdmin on &lt;a href="http://localhost:5050" rel="noopener noreferrer"&gt;http://localhost:5050&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Step 5: Access pgAdmin in Browser
&lt;/h3&gt;

&lt;p&gt;Open your browser and go to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:5050
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  step 6: Add a New Server in pgAdmin
&lt;/h3&gt;

&lt;p&gt;After logging into pgAdmin:&lt;/p&gt;

&lt;p&gt;Click "Query Tool Workspace" (tool-&amp;gt; query tool) in the dashboard.&lt;br&gt;
Under the General tab, fill the following information&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;server name: postgres&lt;/li&gt;
&lt;li&gt;Port: 5432 (port you mentioned while running postgres)&lt;/li&gt;
&lt;li&gt;Host Name: my-postgres (your postgres container name or service name)&lt;/li&gt;
&lt;li&gt;Username: admin (mentioned while running postgres container)&lt;/li&gt;
&lt;li&gt;Password: secret (your postgres password here)&lt;/li&gt;
&lt;li&gt;Database: mydb (database name)&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6f0esncjzotxyltmrjpm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6f0esncjzotxyltmrjpm.png" alt="Image description" width="800" height="642"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Step 7: run sample query
&lt;/h3&gt;

&lt;p&gt;to ensure all is working properly run the following queries in pgAdmin's query space&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Create Table Users&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    username VARCHAR(255) UNIQUE NOT NULL, 
    password_hash VARCHAR(255) NOT NULL
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.Insert a user in users Table&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO users (username, password_hash) VALUES ('your_username', 'your_hashed_password');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.query all users from database&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🚀 Using Docker-compose
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1.Create docker-compose.yaml file
&lt;/h3&gt;

&lt;p&gt;docker-compose.yaml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.8'

services:
  postgres:
    image: postgres:15
    container_name: postgres
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres123
      POSTGRES_DB: mydb
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data

  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: admin123
    ports:
      - "5050:80"
    depends_on:
      - postgres
    volumes:
      - pgadmin_data:/var/lib/pgadmin

volumes:
  pgdata:
  pgadmin_data:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  2.Run it
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose up -d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  3. Access pgAdmin on Browser
&lt;/h3&gt;

&lt;p&gt;open browser and enter &lt;a href="https://dev.tourl"&gt;url http://localhost:5050/browser&lt;/a&gt;&lt;br&gt;
now follow the process from &lt;strong&gt;Step 5&lt;/strong&gt; mentioned above&lt;/p&gt;

</description>
      <category>postgressql</category>
      <category>pgadmin</category>
      <category>docker</category>
      <category>postgres</category>
    </item>
    <item>
      <title>🚀 Setting Up PostgreSQL with Prisma ORM in a Node.js Project (Using Docker)</title>
      <dc:creator>Tushar Patil</dc:creator>
      <pubDate>Sun, 18 May 2025 06:11:20 +0000</pubDate>
      <link>https://dev.to/tush03/setting-up-postgresql-with-prisma-orm-in-a-nodejs-project-using-docker-ock</link>
      <guid>https://dev.to/tush03/setting-up-postgresql-with-prisma-orm-in-a-nodejs-project-using-docker-ock</guid>
      <description>&lt;p&gt;In my recent Node.js project, I set up a PostgreSQL database using Prisma ORM—one of the most efficient and type-safe ORMs available. I used docker to run postgres on my linux machine&lt;/p&gt;

&lt;p&gt;Here’s a detailed walkthrough of the setup—from pulling the Docker image to generating the Prisma client. If you're getting started with Prisma and PostgreSQL in Node.js, this guide is for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  🛠️ Prerequisites
&lt;/h2&gt;

&lt;p&gt;Make sure the following are installed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ &lt;a href="https://nodejs.org/" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; (v14+ recommended)&lt;/li&gt;
&lt;li&gt;✅ &lt;a href="https://www.docker.com/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;✅ &lt;a href="https://www.npmjs.com/" rel="noopener noreferrer"&gt;npm&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Step 1: Pull PostgreSQL Docker Image
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker pull postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 2: Run PostgreSQL Container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--name&lt;/span&gt; my-postgres &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_USER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;admin &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;secret &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_DB&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mydb &lt;span class="nt"&gt;-p&lt;/span&gt; 5432:5432 &lt;span class="nt"&gt;-d&lt;/span&gt; postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔍 This sets up a PostgreSQL container with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Username: admin&lt;/li&gt;
&lt;li&gt;Password: secret&lt;/li&gt;
&lt;li&gt;Database name: mydb&lt;/li&gt;
&lt;li&gt;Port: Exposes DB on localhost:5432&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Step 3: Init NodeJs project
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Install Prisma
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install prisma --save-dev
npm install @prisma/client
npx prisma init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔐 Step 5: Configure .env
&lt;/h3&gt;

&lt;p&gt;add DATABASE_URL in .env file&lt;br&gt;
&lt;code&gt;&lt;br&gt;
DATABASE_URL="postgresql://admin:secret@localhost:5432/mydb?schema=public"&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;admin: PostgreSQL username&lt;/li&gt;
&lt;li&gt;secret: PostgreSQL password&lt;/li&gt;
&lt;li&gt;localhost: Host of the DB server&lt;/li&gt;
&lt;li&gt;5432: PostgreSQL's default port&lt;/li&gt;
&lt;li&gt;mydb: Database name&lt;/li&gt;
&lt;li&gt;schema=public: Default schema in PostgreSQL&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  📝 Step 6: Define Your Prisma Schema
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String?
  createdAt DateTime @default(now())
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ⚙️ Step 7: Migrate and Generate Prisma Client
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx prisma migrate dev --name init
npx prisma generate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;--&lt;br&gt;
migrate dev creates migration files and updates the DB&lt;br&gt;
generate creates the Prisma client for querying&lt;/p&gt;


&lt;h3&gt;
  
  
  Step 8: Test the Database Connection
&lt;/h3&gt;

&lt;p&gt;Let’s write a quick script to ensure everything’s working as expected.&lt;/p&gt;

&lt;p&gt;Create a script.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

async function main() {
  const user = await prisma.user.create({
    data: {
      email: 'abc@example.com',
      name: 'Tushar',
    },
  });

  console.log('User created:', user);

  const allUsers = await prisma.user.findMany();
  console.log('All users:', allUsers);
}

main()
  .catch(e =&amp;gt; {
    console.error(e);
    process.exit(1);
  })
  .finally(async () =&amp;gt; {
    await prisma.$disconnect();
  });

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Run the Script
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node script.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User created: { id: 1, email: 'abc@example.com', name: 'Tushar', createdAt: 2025-05-18T... }
All users: [ { id: 1, email: 'abc@example.com', name: 'Tushar', createdAt: 2025-05-18T... } ]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🎉 Congratulations! You've successfully connected Node.js to a PostgreSQL database running inside a Docker container using Prisma.&lt;/p&gt;

</description>
      <category>node</category>
      <category>postgressql</category>
      <category>prisma</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
