Connecting to Databases

+15 Mana ✨

In Next.js, you can connect to your database directly inside Server Components or Server Actions. You do not need to create separate API routes for internal data fetching.

Best Practices

  • Server-only: Ensure your database logic runs only on the server.
  • Caching: Database queries in Server Components are not automatically cached (unlike fetch), so consider using unstable_cache or the use cache directive (Next.js 16) if needed.

Common ORMs include Prisma and Drizzle.

✓ Completed