Prisma: 2.20.0 Release

Release date:
March 30, 2021
Previous version:
2.19.0 (released March 16, 2021)
Magnitude:
2,489 Diff Delta
Contributors:
9 total committers
Data confidence:
Commits:

69 Commits in this Release

Ordered by the degree to which they evolved the repo in this version.

Authored March 29, 2021
Authored March 24, 2021
Authored March 17, 2021
Authored March 26, 2021
Authored March 29, 2021
Authored March 30, 2021
Authored March 30, 2021
Authored March 30, 2021
Authored March 25, 2021
Authored March 26, 2021
Authored March 30, 2021
Authored March 30, 2021
Authored March 30, 2021
Authored March 26, 2021
Authored March 26, 2021
Authored March 25, 2021
Authored March 26, 2021
Authored March 26, 2021

Top Contributors in 2.20.0

williamluke4
Jolg42
timsuchanek
renovate-bot
paularah
Iamshankhadeep
janpio
madebysid
matthewmueller

Directory Browser for 2.20.0

We haven't yet finished calculating and confirming the files and directories changed in this release. Please check back soon.

Release Notes Published

Today, we are excited to share the 2.20.0 stable release 🎉

🌟 Help us spread the word about Prisma by starring the repo or tweeting about the release. 🌟 

Major improvements & new features

Count on relations (Preview)

This highly requested feature is now in Preview. You can now 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.

For example, counting the number of posts that an user has written:

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

The structure of the returned User objects is as follows:

{
  id: 1,
  email: '[email protected]',
  name: 'Alice',
  _count: { posts: 2 }
}

You can enable this featrues with the selectRelationCount feature flag:

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

There may be some rough edges during the Preview period. If you run into any problems, you can reach us in this issue.

Node-API is now in Preview

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.

You can enable this feature with the napi feature flag:

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

Enabling the Node-API will not affect your workflows in any way, the experience of using Prisma will remain exactly the same.

The Node-API has different runtime characteristics than the current communication layer between Node.js and Rust.

There may be some rough edges during the Preview period. If you run into any problems, you can reach us in this issue.

New push operation available for arrays on PostgreSQL

PostgreSQL supports array data structures (sometimes also called scalar lists). As an example, consider the permissions field on the following User model:

model User {
  id          Int @id @default(autoincrement())
  permissions String[]
}

As of this release, you can append a new item to existing lists atomically with the push command:

await prisma.user.update({
  where: { id: 42 },
  data: {
    permission: {
      push: "chat:read",
    },
  },
})

Learn more in this issue.

groupBy and createMany are now Generally Available

For the pioneers among you, you can now remove the groupBy and createMany from your Preview features:

 generator client {
   provider        = "prisma-client-js"
-  previewFeatures = ["groupBy", "createMany"]
 }

Learn more in our documentation about groupBy and createMany.

Prisma Client Go now supports BigInt, Decimal and Bytes

Prisma Client Go continues to get more powerful every release. With this release, we've added support for more native database types: BigInt, Decimal and Bytes:

var views db.BigInt = 1
bytes := []byte("abc")
dec := decimal.NewFromFloat(1.23456789)
created, err := client.User.CreateOne(
  db.User.Picture.Set(bytes),
  db.User.Balance.Set(dec),
  db.User.Views.Set(views),
).Exec(ctx)

Breaking changes

The @prisma/cli package has reached its end of life

For all you holdovers, you've seen warnings like this for a couple months now:

warn @prisma/cli has been renamed to prisma.
Please uninstall @prisma/cli: npm remove @prisma/cli
And install prisma: npm i prisma

It's now time to upgrade. Follow the instructions and switch over to the new prisma package today:

npm

npm remove @prisma/cli
npm install -D prisma

Thanks to this change, running npx prisma will now always invoke the right Prisma CLI, no matter what your local setup looks like.

Yarn

yarn remove @prisma/cli
yarn add -D prisma

Upcoming breaking changes in the next version (2.21.0)

.aggregate will change to return null in 2.21.0

Subscribe to this issue for updates on how to prepare your code.

Fixes and improvements

Prisma Migrate

Prisma Client

Language tools (e.g. VS Code)

Security Fixes

We fixed two security issues:

Big thanks to @erik-krogh (Erik Krogh Kristensen) and @Ry0taK for reporting these issues.

Credits

Huge thanks to @endor, @iBluemind, @matthewmueller, @paularah, @Iamshankhadeep for helping!

📺 Join us for another "What's new in Prisma" livestream

Learn about the latest release and other news from the Prisma community by joining us for another "What's new in Prisma" livestream.

The stream takes place on Youtube on Thursday, April 01 at 5pm Berlin | 8am San Francisco.