Files
Ankur Datta 92a9d2840d Add Prisma ORM example to Next.js examples (#75290)
- A Next.js starter app using [Prisma
Postgres](https://www.prisma.io/postgres) and Prisma ORM

This PR adds a new example demonstrating how to integrate Prisma ORM
with a Next.js application. The example includes:

- Setup instructions for Prisma Postgres
- Example models and queries
- Basic CRUD operations using Prisma

---------

Co-authored-by: Nikolas <nikolas.burk@gmail.com>
Co-authored-by: Alex Martin <alex.martin@vercel.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2025-07-15 08:48:35 -07:00

23 lines
666 B
TypeScript

import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
const url = new URL(request.url);
const page = parseInt(url.searchParams.get("page") || "1");
const postsPerPage = 5;
const offset = (page - 1) * postsPerPage;
// Fetch paginated posts
const posts = await prisma.post.findMany({
skip: offset,
take: postsPerPage,
orderBy: { createdAt: "desc" },
include: { author: { select: { name: true } } },
});
const totalPosts = await prisma.post.count();
const totalPages = Math.ceil(totalPosts / postsPerPage);
return NextResponse.json({ posts, totalPages });
}