github prisma/prisma 2.4.0

latest releases: 5.14.0, 5.13.0, 5.12.1...
3 years ago

Today, we are issuing the 2.4.0 stable release.

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

Major improvements

Order by multiple fields

A long-awaited feature - the ability to order by multiple fields in Prisma Client is finally here!

Until now you could only order by a single scalar field of a model. The API design however was already prepared for ordering multiple fields with the object syntax we have. Instead of just one property, that orderBy object can now have as many fields as you want! The order of the fields hereby determines the order of the returned list (see example below).

Note: As this is an incremental change in the API, we introduce this feature without a feature flag.

You can use it like so:

// order by `age` descending and then by `name` ascending
const users = await prisma.user.findMany({
  orderBy: {
    age: 'desc',
    name: 'asc'
  }
})

As mentioned by the comment, the returned objects in users are ordered first by age (descending), and then by name (ascending).

📚 Documentation: Sort on multiple fields

Top-level Client Methods: $ dollar prefix for top-level Prisma Client methods

In recent versions, we introduced a couple of top-level methods in Prisma Client (e.g. prisma.transaction() and prisma.use()) in preview mode. The immediate feedback was that the denylist for model names grew - which breaks Prisma schemas where a model is called Transaction, transaction, use, or Use. And the list goes on...

In order to have a future-proof API, that allows maximum expressibility in terms of model names, we decided to prefix all non-query methods with a dollar sign $. That means Prisma Client will from now on ship with the following methods:

Pre-existing

  • $disconnect
  • $connect
  • $on
  • $queryRaw
  • $executeRaw

Still in preview

  • $use
  • $transaction

The preview methods have already been renamed, the pre-existing methods like connect are still available, you just get a deprecation warning. They will be available for a few more releases with an alias, so no hurry to update them yet.

Updates in Prisma Studio

With this release, we shipped a number of improvements for Prisma Studio:

  • Refreshed design
  • Moved the Reload button from the right of the databrowser to the left
  • Moved the Pending Actions bar from the bottom of the databrowser to the top right
  • Removed the sidebar; to open a model, you can now press the New Tab button on the top
  • Removed the code editor
  • Removed the tree view
  • Added ability to view and edit JSON fields

Try out Prisma Studio in the online demo or in your Prisma project by running:

npx prisma studio --experimental

Preview features

Changes to middlewares and transactionApi

As mentioned above, we ar changing the names of some the top-level Prisma Client methods. This affects the two preview features middlewares and transactionApi.

middlewares

You still need to enable the preview feature via the generator block in your Prisma schema to access it:

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

Before

prisma.on()

After

prisma.$on()
transactionApi

You still need to enable the preview feature via the generator block in your Prisma schema to access it:

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

Before

prisma.transaction()

After

prisma.$transaction()

Already existing preview features from 2.1.0, 2.2.0, and 2.3.0

Just a quick reminder:

  • In version 2.1.0 we introduced two experimental features, namely connectOrCreate and transactionApi.
  • In 2.2.0 we introduced aggregateApi.
  • In 2.3.0 we introduced middlewares and the distinctApi.

In case they're useful for you, please give them a try and share your feedback! These features remain in preview in this release.

🌟 Help us spread the word about Prisma

To help spread the word about Prisma, we'd very much appreciate if you would star this repo 🌟 And if you're excited about the features in this week's release, then help us and share it on Twitter.

Fixes and improvements

prisma

prisma-client-js

migrate

language-tools

studio

prisma-engines

Don't miss a new prisma release

NewReleases is sending notifications on new releases.