Setting Up Prisma (Latest Approach)
I previously wrote a blog on how to set up Prisma and learn its basics. The old guide still works if you want to understand Prisma fundamentals, but the setup process has changed quite a bit since then.
If you still want to check out that older guide, you can read it here: https://fardeen.tech/blogs/cm7ewul930000gs9o85b6ml42
Now, let’s walk through the new, up-to-date way of setting up Prisma in your project, including Prisma Accelerate for faster queries and an optional Prisma Postgres instance.
1. Install Prisma CLI and tsx.
npm install prisma tsx --save-dev2. Install Prisma Client & Accelerate Extension.
npm install @prisma/extension-accelerate @prisma/client3. Initialize Prisma in your project.
Now some changes here: 
1. --output ../app/generated/prisma  : allow us to define the path for the converted database schema.
2. --db : if you also want to get a postgres database instance from prisma, this flag allows you to initialize a database instance and put the database url to .env file automatically.
npx prisma init --db --output ../app/generated/prismaIf you’re not using Prisma Postgres, you can skip the
--dbflag and manually update your.envfile with your own database connection string.
4. Define database schema
In your schema.prisma file define the your schema.
model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String?
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}Also, when using Accelerate in production, your datasource block should have both DATABASE_URL and DIRECT_URL 
datasource db {
  provider  = "postgresql"
  url       = env("DATABASE_URL") // accelerate-optimized url
  directUrl = env("DIRECT_URL")   // direct db url for migrations
}5. Migrate the database.
npx prisma migrate dev --name init6. Generate Prisma Client (Accelerate-Friendly)
When using Accelerate, you can skip the local query engine binary in production:
npx prisma generate --no-engine7. Create an prisma singleton file
create an lib/prisma.ts file and put this code in it:
import { PrismaClient } from '../app/generated/prisma'
import { withAccelerate } from '@prisma/extension-accelerate'
const globalForPrisma = global as unknown as { 
    prisma: PrismaClient
}
const prisma = globalForPrisma.prisma || new PrismaClient().$extends(withAccelerate())
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
export default prisma;8. Import the prisma in your app
import prisma from "@lib/prisma"
export default function App() {
	const fetchUser = async () => {
		const user = await prisma.user.findMany();
		return user;
	}
	
	return ()
}- Summary of changes from old setup
--dbflag can now provision a Prisma-hosted Postgres database automatically.--outputlets you customize Prisma Client location.Added
directUrlinschema.prismafor migrations.Use
--no-enginewhen generating Prisma Client with Accelerate.Updated singleton import to use
@prisma/clientdirectly.Clarified local vs production Accelerate behavior.
Hope this blog will help you, see you in the next one till than kepp making memes using memehub dot mom.
@fardeentwt