Releases ยท prisma/prisma ยท GitHub

August 12, 2025 at 12:00 AMai_discoveryinfo

Product

SonarQube

developmenttoolsprogramming

Update Details

Comprehensive information about this update

Full Content

Release Notes
Today, we are excited to share the 6.14.0 stable release ๐ŸŽ‰ ๐ŸŒŸ Star this repo for notifications about new releases, bug fixes & features โ€” or follow us on X! Highlights @unique attributes for SQL views (Preview) Last release, we improved the robustness of SQL views defined in the Prisma schema. Views are virtual tables that don't allows for defining unique constraints, indexes or foreign keys in the underlying database. However, as an application developer, it can be convenient to also define relationships involving views or paginate them using cursors. We've received this feedback from several people who had been using views in that way with Prisma ORM, so in this release we're re-introducing the @unique attribute for views. This attribute enables: relationships involving views findUnique queries, cursor-based pagination & implicit ordering for views Here's an example schema using @unique and defining a relationship from a model to a view: model User { id Int @id @default(autoincrement()) email String @unique posts Post[] stats UserPostStats? @relation(fields: [email], references: [userEmail]) } model Post { id Int @id @default(autoincrement()) title String published Boolean @default(false) createdAt DateTime @default(now()) authorId Int? author User? @relation(fields: [authorId], references: [id]) } view UserPostStats { userEmail String @unique totalPosts BigInt? publishedPosts BigInt? unpublishedPosts BigInt? latestPostDate DateTime? @db.Timestamp(6) user User? } Expand to view the SQL code for this view CREATE OR REPLACE VIEW "UserPostStats" AS SELECT u.email AS "userEmail", u.name AS "userName", COUNT(p.id) AS "totalPosts", COUNT(CASE WHEN p.published = true THEN 1 END) AS "publishedPosts", COUNT(CASE WHEN p.published = false THEN 1 END) AS "unpublishedPosts", MAX(p."createdAt") AS "latestPostDate" FROM "User" u LEFT JOIN "Post" p ON u.id = p."authorId" GROUP BY u.id, u.email, u.name; You can now query this view and its relationship using include: const userPostS

Published At

Tuesday, August 12, 2025

12:00:00 AM

Discovered At

Monday, August 25, 2025

10:25:39 PM

Confidence

1