October 02, 2021

What's new in Prisma? (Q3/21)

Learn about everything that has happened in the Prisma ecosystem and community from July to September 2021.

Overview

Releases & new features

As previously announced, Prisma has adopted SemVer strictly and we had our first major release during this quarter (version 3.0.1), which had some breaking changes.

For all the breaking changes, there are guides and documentation to assist you with the upgrade.

During that major release, many Preview features were promoted to General Availability. This means that they are ready for production use and have passed rigorous testing both internally and by the community.

We recommend that you read through the release notes carefully and make sure that you've correctly upgraded your application.


Our engineers have been hard at work issuing new releases with many improvements and new features every two weeks. Here is an overview of the most exciting features that we've launched in the last three months.

You can stay up-to-date about all upcoming features on our roadmap.

MongoDB is now in preview 🚀

We're thrilled to announce that Prisma now has Preview support for MongoDB since version 2.27.0.

MongoDB support has passed rigorous testing internally and by the Early Access participants and is now ready for broader testing by the community. However, as a Preview feature, it is not production-ready. To read more about what preview means, check out the maturity levels in the Prisma docs.

We would love to know your feedback! If you have any comments or run into any problems we're available in this issue. You can also browse existing issues that have the MongoDB label.

Microsoft SQL Server and Azure SQL Connector is now Generally Available

We're excited to announce that Prisma support for Microsoft SQL Server and Azure SQL is Generally Available and ready for production!

Since we released Prisma Client for General Availability over a year ago with support for PostgreSQL, MySQL, SQLite, and MariaDB, we've heard from thousands of engineers about how the Prisma ORM is helping them be more productive and confident when building data-intensive applications.

After passing rigorous testing internally and by the community over the last year since the Preview release in version 2.10.0, we're thrilled to bring Prisma's streamlined developer experience and type safety to developers using Microsoft SQL Server and Azure SQL in General Availability 🚀.

Interested in Prisma’s upcoming Data Proxy for serverless backends? Get notified! 👀

Database connection management in serverless backends is challenging: taming the number of database connections, additional query latencies for setting up connections, etc.

At Prisma, we're working on a Prisma Data Proxy that makes integrating traditional relational and NoSQL databases in serverless Prisma-backed applications a breeze. If you are interested, you can sign up to get notified of our upcoming Early Access Program here:

https://pris.ly/prisma-data-proxy


Get notified

Referential Actions is now Generally Available

Referential Actions is a feature that allows you to control how relations are handled when an entity with relations is changed or deleted. Typically this is done when defining the database schema using SQL.

Referential Actions allows you to define this behavior from the Prisma schema by passing in the onDelete and onUpdate arguments to the @relation attribute.

For example:

model LitterBox {
id Int @id @default(autoincrement())
cats Cat[]
full Boolean @default(false)
}
model Cat {
id String @id @default(uuid())
boxId Int
box LitterBox @relation(fields: [boxId], references: [id], onDelete: Restrict)
}

Here, you would not be able to delete a LitterBox as long as there still is a Cat linked to it in your database, because of the onDelete: Restrict annotation. If we had written onDelete: Cascade, deleting a LitterBox would also automatically delete the Cats linked to it.

Referential Actions was first released in 2.26.0 with the referentialActions Preview flag. Since then, we've worked to stabilize the feature.

We're delighted to announce that Referential Actions is now General Available, meaning it is enabled by default.

Referential Integrity is now in Preview

Relational databases typically ensure integrity between relations with foreign key constraints, for example, given a 1:n relation between User:Post, you can configure the deletion of a user to cascade to posts so that no posts are left pointing to a User that doesn't exist. In Prisma, these constraints are defined in the Prisma schema with the @relation() attribute.

However, databases like PlanetScale do not support defining foreign keys. To work around this limitation so that you can use Prisma with PlanetScale, we're introducing a new referentialIntegrity setting in Preview.

This was initially introduced in version 2.24.0 of Prisma with the planetScaleMode preview feature and setting. Starting with the 3.1.1 release both have been renamed to referentialIntegrity.

The setting lets you control whether referential integrity is enforced by the database with foreign keys (default), or by Prisma, by setting referentialIntegrity = "prisma".

Setting Referential Integrity to prisma has the following implications:

  • Prisma Migrate will generate SQL migrations without any foreign key constraints.
  • Prisma Client will emulate foreign key constraints and referential actions on a best-effort basis.

You can give it a try in version 3.1.1 by enabling the referentialIntegrity preview flag:

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
referentialIntegrity = "prisma"
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
}

After changing referentialIntegrity to prisma, make sure you run prisma generate to ensure that the Prisma Client logic has been updated.

Note that Referential Integrity is set to prisma by default when using MongoDB.

Learn more about it in our documentation, and share your feedback.

Named Constraints

Starting with Prisma 3, the names of database constraints and indexes are reflected in the Prisma schema. This means that Introspection with db pull as well as migrate and db push will work towards keeping your constraint and index names in sync between your schema and your database.

Additionally, a new convention for default constraint names is now built into the Prisma Schema Language logic. This ensures reasonable, consistent defaults for new greenfield projects. The new defaults are more consistent and friendlier to code generation. It also means that if you have an existing schema and/or database, you will either need to migrate the database to the new defaults, or introspect the existing names.

⚠️ This means you will have to make conscious choices about constraint names when you upgrade. Please read the Named Constraints upgrade guide for a detailed explanation and steps to follow. ⚠️

Seeding with prisma db seed has been revamped and is now Generally Available

When developing locally, it's common to seed your database with initial data to test functionality. In version 2.15 of Prisma, we initially introduced a Preview version of seeding using the prisma db seed command.

We're excited to share that the prisma db seed command has been revamped and simplified with a better developer experience and is now Generally Available.

The seeding functionality is now just a hook for any command defined in "prisma"."seed" in your package.json.

For example, here's how you would define a TypeScript seed script with ts-node:

  1. Open the package.json of your project
  2. Add the following example to it:
// package.json
"prisma": {
"seed": "ts-node prisma/seed.ts"
}

Expand to view an example seed script
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function main() {
const alice = await prisma.user.upsert({
where: { email: 'alice@prisma.io' },
update: {},
create: {
email: 'alice@prisma.io',
name: 'Alice',
},
})
console.log({ alice })
}
main()
.catch((e) => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})

This approach gives you more flexibility and makes fewer assumptions about how you choose to seed. You can define a seed script in any language as long as it's just a terminal command.

For example, here's how you would seed using an SQL script and the psql CLI tool.

// package.json
"prisma": {
"seed": "psql --dbname=mydb --file=./prisma/seed.sql"
}

🚨 Please note that if you already have a seed script that worked created in versions prior, you will need to add the script to prisma.seed in your package.json and adapt the script to the new API. Read more in the Breaking Changes section and the seeding docs for a complete explanation and walkthroughs of common use cases.

Node-API is Generally Available

Node-API is a new technique for binding Prisma's Rust-based query engine directly to Prisma Client. This reduces the communication overhead between the Node.js and Rust layers when resolving Prisma Client's database queries.

Earlier versions of Prisma (since version 2.0.0) used the Prisma Query Engine binary, which runs as a sidecar process alongside your application and handles the heavy lifting of executing queries from Prisma Client against your database.

In 2.20.0 we introduced a Preview feature, the Node-API library, as a more efficient way to communicate with the Prisma Engine binary. Using the Node-API library is functionally identical to running the Prisma engine binary while reducing the runtime overhead by making direct binary calls from Node.js.

Starting with the 3.0.1 release we're making the Node-API library engine the default query engine type. If necessary for your project, you can fall back to the previous behavior of a sidecar Prisma Engine binary, however, we don't anticipate a reason to do so.

If you've been using this preview feature, you can remove the nApi flag from previewFeatures in your Prisma Schema.

Learn more about the Query Engine in our documentation.

New features for the Prisma Client API

Order by Aggregate in Group By is Generally Available

Let's say you want to group your users by the city they live in and then order the results by the cities with the most users. Order by Aggregate Group allows you to do that, for example:

await prisma.user.groupBy({
by: ['city'],
_count: {
city: true,
},
orderBy: {
_count: {
city: 'desc',
},
},
}),

Expand to view the underlying Prisma schema
model User {
id Int @id @default(autoincrement())
email String @unique
city String
name String?
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author User? @relation(fields: [authorId], references: [id])
authorId Int?
}

Order by Aggregate Group was initially released as a Preview feature in 2.21.0.

Starting with the 3.0.1 release release it is Generally Available 🤩

If you've been using this Preview feature, you can remove the orderByAggregateGroup flag from previewFeatures in your Prisma Schema.

Learn more about this feature in our documentation.

Order by Relation is Generally Available

Ever wondered how you can query posts and have the results ordered by their author's name?

With Order by Relations, you can do this with the following query:

await prisma.post.findMany({
orderBy: {
author: {
name: 'asc',
},
},
include: {
author: true,
},
})

Expand to view the underlying Prisma schema
```prisma
model User {
id Int @id @default(autoincrement())
email String @unique
city String
name String?
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author User? @relation(fields: [authorId], references: [id])
authorId Int?
}
```

Order by Relation was initially released in Preview in 2.16.0.

Starting with the 3.0.1 release it is Generally Available 🧙

If you've been using this preview feature, you can remove the orderByRelation flag from previewFeatures in your Prisma Schema.

Learn more about this feature in our documentation.

Select Relation Count is Generally Available

Select Relation Count allows you to count the number of related records by passing _count to the select or include options and then specifying which relation counts should be included in the resulting objects via another select.

Select Relation Count helps you query counts on related models, for example, counting the number of posts per user:

const users = await prisma.user.findMany({
include: {
_count: {
select: { posts: true },
},
},
})

Expand to view the structure of the returned `users`
[
{
id: 2,
email: 'bob@prisma.io',
city: 'London',
name: 'Bob',
_count: { posts: 2 },
},
{
id: 1,
email: 'alice@prisma.io',
city: 'Berlin',
name: 'Alice',
_count: { posts: 1 },
},
]

If you've been using this Preview feature, you can remove the selectRelationCount flag from previewFeatures in your Prisma Schema.

Learn more about this feature in our documentation.

Full-Text Search is now in preview for PostgreSQL

We're excited to announce that Prisma Client now has preview support for Full-Text Search on PostgreSQL since version 2.30.0 for the JS/TS client and since version 3.1.1 for the Go client.

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch"]
}
model Post {
id Int @id @default(autoincrement())
title String @unique
body String
status Status
}
enum Status {
Draft
Published
}

You'll see a new search field on your String fields that you can query on. Here is an example:

// returns all posts that contain the words cat *or* dog.
const result = await prisma.post.findMany({
where: {
body: {
search: 'cat | dog',
},
},
})

Expand to view the underlying Prisma schema
```prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch"]
}
model Post {
id Int @id @default(autoincrement())
title String @unique
body String
status Status
}
enum Status {
Draft
Published
}
```

You can learn more about how the query format works in our documentation. We would love to know your feedback! If you have any comments or run into any problems we're available in this in this Github issue.

Interactive transactions are now in Preview

One of our most debated feature requests- Interactive Transactions, is now in Preview.

Interactive Transactions are a double-edged sword. While they allow you to ignore a class of errors that could otherwise occur with concurrent database access, they impose constraints on performance and scalability.

While we believe there are better alternative approaches, we certainly want to ensure people who absolutely need them have the option available.

You can opt-in to Interactive Transactions by setting the interactiveTransactions preview feature in your Prisma Schema:

generator client {
provider = "prisma-client-js"
previewFeatures = ["interactiveTransactions"]
}

Note that the interactive transactions API does not support controlling isolation levels or locking for now.

You can find out more about implementing use cases with transactions in the docs, and share your feedback.

We regularly add new features to the Prisma Client API to enable more powerful database queries that were previously only possible via plain SQL and the $queryRaw escape hatch.

Community

We wouldn't be where we are today without our amazing community of developers. Our Slack has more than 40k members and is a great place to ask questions, share feedback and initiate discussions all around Prisma.


Join Slack

Meetups

Prisma Meetup #8
Prisma Meetup #8

Prisma, TypeScript, AzureSQL, Serverless, FullStack…oh my! - Davide Mauri

Full-Stack Jamstack Fun - Mike Cavaliere

Victor Iris - Boosting development with Prisma & GraphQL

GraphQL Berlin #23
GraphQL Berlin #23

All you (n)ever wanted to know about Introspection - Stephan Schneider

How to edge cache GraphQL APIs - Max Stoiber

Using GraphQL to manage contributions from multiple teams - Franco Risso

TypeScript Berlin Meetup #7
TypeScript Berlin Meetup #7

TypeScript pitfalls you should avoid for great Developer Experience - Anil Kumar

RTW: designing a library for real-time queries - Simon Knott

Mughees Ilyas - Understanding Alias types and tuples 101

Prisma meetup #7
Prisma meetup #7

What's new at PlanetScale? - Nick Van Wiggeren

Deploying Prisma on Lambda using the CDK - Ryan Dsouza

Database Design 101 - Harsh Singh

Prisma Meetup Korea
Prisma Meetup Korea

데이터베이스 마이그레이션 및 prisma introspection 을 통한 prisma로의 손쉬운 - Hyochan Jang

프로덕션 레벨에서 nestjs와 prisma - Han Sangjin

Next generation CMS and Graphql API via keystonejs and prisma - Jed Watson

JS Monthly Online Meetup #17
JS Monthly Online Meetup #17

Double up your component and integration tests with Supertest & Nock - Lewis Prescott

Heavily Connected Data Applications - Daniel Olavio Ferreira

Anonymous video calling app using machine learning - Ben Butterworth

JS Monthly Lunchtime Meetup #7
JS Monthly Lunchtime Meetup #7

Fully featured auth for your Next.js-Prisma app with Clerk - Peter Perlepes

Making MongoDB Type-Safe with Prisma - Daniel Norman

GraphQL Nairobi Meetup + a raffle
GraphQL Nairobi Meetup + a raffle

Generating GraphQL Queries - Julian Mayorga

Building a GraphQL API with Prisma - Joey Ng'ethe & Mahmoud Abdelwahab

Connect Dev Africa Meetup #2
Connect Dev Africa Meetup #2

Building Accessible Design Systems with React - Segun Adebayo

Elarian - A Tale of Communication & Data - Anthony Kiplimo


Videos, livestreams & more

What's new in Prisma

Every other Thursday, Daniel Norman and Mahmoud Abdelwahab discuss the latest Prisma release and other news from the Prisma ecosystem and community. If you want to travel back in time and learn about a past release, you can find all the shows from this quarter here:

Videos

We published a lot of videos during this quarter on our YouTube channel, make sure you check them out and subscribe to not miss out on future videos. We also published a couple of interviews where we go over different topics.

Subscribe on YouTube

Written content

During this quarter, we published several technical articles that you might find useful:

We also published two success stories of companies adopting Prisma:

Prisma appearances

This quarter, several Prisma folks have appeared on external channels and livestreams. Here's an overview of all of them:

New Prismates

Here are the awesome new Prismates who joined Prisma this quarter:


Alex Emerich
Alex EmerichTechnical writer | September 2021
😆 Fun Fact

I am ambidextrous 🙂

❓ Why are you joining Prisma?

I joined Prisma because I believe it is an amazing product with game-changing potential. The Prisma community is passionate and exciting to be a part of. I get to work with kind, intelligent, and driven people. What’s not to like?

Nika Music
Nika MusicMarketing Associate Intern | July 2021
😆 Fun Fact

I've lived in nine countries, and because of that I taught myself my 'mother tongue' only when I was 13.

❓ Why are you joining Prisma?

The reason I joined Prisma was because I was always curious about the startup life, and it seemed like a very supportive environment to be in, which is exactly that I needed after university.

Jakub Elżbieciak
Jakub ElżbieciakSoftware Engineer (Scale Team) | July 2021
😆 Fun Fact

I've built my first database-backed application when I was 10 years old and the stack was: Borland Delphi, Object Pascal and MS Access

❓ Why are you joining Prisma?

I gave the ORM a try and loved the developer experience! In addition, the challenge of architecting and launching the cloud product is really appealing

Tasin Ishmam
Tasin IshmamDeveloper Success Engineer at Prisma | July 2021
😆 Fun Fact

I am totally obsessed with computers from the '80s.

❓ Why are you joining Prisma?

I love the fact that Prisma is dedicated to improving developers' experience and working closely with the community to build excellent open-source software and products. I admire the ambitious product vision of Prisma and believe that it will unlock workflows and opportunities that were not previously possible. It's amazing to work with such a talented team on something that feels genuinely impactful.

Also, we're hiring for various roles! If you're interested in joining us and becoming a Prismate, check out our jobs page.


Explore Jobs

Stickers

We love seeing laptops that are decorated with Prisma stickers, so we're shipping sticker packs for free to our community members! In this quarter, we've sent out over 300 sticker packs to developers that are excited about Prisma!


Order Stickers

What's next?

The best places to stay up-to-date about what we're currently working on are GitHub issues and our public roadmap. (Mongo DB support coming soon 👀)

You can also engage in conversations in our Slack channel, start a discussion on GitHub or join one of the many Prisma meetups around the world.

Join the discussion

Follow @prisma on Twitter

Don’t miss the next post!

Sign up for the Prisma newsletter