Skip to content

Commit

Permalink
Merge pull request #2 from abhishekHegde2000/test-branch
Browse files Browse the repository at this point in the history
prisma and mongodb setup.
  • Loading branch information
abhishekHegde2000 authored Nov 23, 2023
2 parents 4232dfb + 37d6395 commit 1a6b7bb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts

.env
.env


Binary file added CodeSnap/code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

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


model Note {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
content String?
userId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("notes")
}
17 changes: 17 additions & 0 deletions src/lib/db/prisma.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PrismaClient } from "@prisma/client";

const prismaClientSingleton = () => {
return new PrismaClient();
};

type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;

const globalForPrisma = globalThis as unknown as {
prisma: PrismaClientSingleton | undefined;
};

const prisma = globalForPrisma.prisma ?? prismaClientSingleton();

export default prisma;

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;

0 comments on commit 1a6b7bb

Please sign in to comment.