-
Notifications
You must be signed in to change notification settings - Fork 1.5k
update prisma postgres example #8399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update prisma postgres example #8399
Conversation
WalkthroughThis PR modernizes the Prisma Postgres example by migrating from the Accelerate extension to the PostgreSQL adapter pattern. It updates dependencies, simplifies documentation, removes separate caching and query examples, and consolidates functionality into a single entry point demonstrating core CRUD operations. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Pre-merge checks❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
databases/prisma-postgres/src/index.ts (1)
34-35: Add safety check for array access.Direct access to
user.posts[0]assumes the posts array has at least one element. While this should be true given the preceding create operation, defensive coding is recommended.Apply this diff:
// Update a post const updatedPost = await prisma.post.update({ - where: { id: user.posts[0].id }, + where: { id: user.posts[0]?.id }, data: { title: "Hello from Prisma Postgres! (updated)" }, });Or add an explicit check:
// Update a post + if (user.posts.length === 0) { + throw new Error("No posts found for user"); + } const updatedPost = await prisma.post.update({ where: { id: user.posts[0].id }, data: { title: "Hello from Prisma Postgres! (updated)" }, });databases/prisma-postgres/README.md (1)
19-50: Consider mentioning npm/pnpm alternatives.The README assumes Bun is available. While Bun is fast and modern, consider mentioning npm or pnpm alternatives for broader accessibility, especially since the example works with any package manager.
Optional addition after line 19:
cd prisma-postgres bun install +# Or use npm install / pnpm installAnd after line 50: ```diff bun run dev +# Or use npm run dev / pnpm run dev</blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used**: Path: .coderabbit.yaml **Review profile**: CHILL **Plan**: Pro <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between e725bc152232a61acc8d26a22f0e547eb9b39f7d and aa2ea8f013917f2ef7f904e88c7bbf0c5e8dd924. </details> <details> <summary>📒 Files selected for processing (5)</summary> * `databases/prisma-postgres/README.md` (1 hunks) * `databases/prisma-postgres/package.json` (1 hunks) * `databases/prisma-postgres/src/caching.ts` (0 hunks) * `databases/prisma-postgres/src/index.ts` (1 hunks) * `databases/prisma-postgres/src/queries.ts` (0 hunks) </details> <details> <summary>💤 Files with no reviewable changes (2)</summary> * databases/prisma-postgres/src/queries.ts * databases/prisma-postgres/src/caching.ts </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>🧬 Code graph analysis (1)</summary> <details> <summary>databases/prisma-postgres/src/index.ts (1)</summary><blockquote> <details> <summary>orm/prisma-mocking-javascript/client.js (1)</summary> * `adapter` (4-4) </details> </blockquote></details> </details> </details> <details> <summary>⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (16)</summary> * GitHub Check: test (orm/nest-graphql) * GitHub Check: test (orm/betterauth-nextjs) * GitHub Check: test (orm/betterauth-astro) * GitHub Check: test (orm/grpc) * GitHub Check: test (orm/nextjs) * GitHub Check: test (orm/authjs-nextjs) * GitHub Check: test (orm/ai-sdk-nextjs) * GitHub Check: test (orm/clerk-nextjs) * GitHub Check: test (orm/clerk-astro) * GitHub Check: test (orm/hapi-graphql) * GitHub Check: test (orm/astro) * GitHub Check: test (orm/cloudflare-workers) * GitHub Check: test (orm/nest-graphql-sdl-first) * GitHub Check: test (orm/nuxt) * GitHub Check: test (orm/sveltekit) * GitHub Check: test (orm/solid-start) </details> <details> <summary>🔇 Additional comments (5)</summary><blockquote> <details> <summary>databases/prisma-postgres/src/index.ts (5)</summary><blockquote> `8-24`: **LGTM!** The user creation with nested post creation demonstrates Prisma's relation handling correctly. Using `Date.now()` for email uniqueness is appropriate for an example. --- `26-31`: **LGTM!** The query correctly demonstrates filtering and including relations. --- `41-43`: **LGTM!** The error handling pattern with `catch` and `finally` ensures proper cleanup via `$disconnect()` regardless of success or failure. --- `5-6`: **The `connectionString` parameter is correct for PrismaPg.** The PrismaPg constructor API accepts `connectionString` as the parameter name, matching the official Prisma documentation. The code at lines 5-6 follows the correct API usage. However, adding validation for the `DATABASE_URL` environment variable is a reasonable defensive coding practice to provide clearer error messages if the variable is missing: ```diff +if (!process.env.DATABASE_URL) { + throw new Error("DATABASE_URL environment variable is not defined"); +} + const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }); const prisma = new PrismaClient({ adapter });Likely an incorrect or invalid review comment.
2-2: This import path is intentional but part of a non-standard Prisma configuration.The schema uses a custom generator with
provider = "prisma-client"andoutput = "./generated", making the import path../prisma/generated/clientcorrect for this setup. However, theprisma/generateddirectory doesn't exist yet—it must be created by runningprisma generatefirst. Additionally, since@prisma/clientis already listed as a dependency, consider using the standard import path instead:-import { PrismaClient } from "../prisma/generated/client"; +import { PrismaClient } from "@prisma/client";This custom generator setup is unconventional and may cause issues if the generated directory is not present or if the custom provider is not properly configured.
Summary by CodeRabbit
Documentation
Chores
✏️ Tip: You can customize this high-level summary in your review settings.