yarn @prisma/client 2.5.0

latest releases: 5.23.0-dev.10, 5.23.0-dev.9, 5.23.0-integration-engines-5-23-0-8-integration-include-field-native-type-data-to-dmmf-f616ccc38c3d791e452ebd52f830a7fad0161650.2...
4 years ago

Today we are excited to share the 2.5.0 stable release.

🌟 Help us spread the word about Prisma by starring the repo ☝️, tweeting about the release or sharing your experience with Prisma on Reddit. 🌟

Major improvements

Middlewares, removing duplicates with distinct and aggregations are now stable

After running in preview mode for a number of releases, we are excited to promote the following features into this stable release:

  • middlewares
  • distinct
  • aggregationsApi

This means you can omit the respective feature flags in the generator block in your Prisma schema:

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

Read on to learn about each feature individually!

Middlewares

Prisma Client's middleware lets you intercept Prisma Client queries to manipulate its parameters and interrogate its result. A middleware is a function that's passed to Prisma Client's $use method.

Middlewares are convenient for a number of use cases, for example:

  • Logging the time taken to perform a type of query
  • Manipulating or validating query parameters
  • Contacting another service upon specific queries

The following example includes two middlewares:

const prisma = new PrismaClient()

prisma.$use(async (params, next) => {
  const result = next(params);
  return result;
}

prisma.$use(async (params, next) => {
  return next(params);
}

📚 Documentation: Middleware

Remove duplicates from query results with distinct

Prisma Client allows you to filter duplicate rows from the response to a findMany query using the distinct option:

const distinctCities = await prisma.user.findMany({
  select: {
    city: true,
    country: true,
  },
  distinct: ["city"],
});

📚 Documentation: Distinct

Aggregations with aggregate

Prisma Client allows you to perform aggregations operations on the number fields (such as Int and Float) of a model - for example, you can get the average age of all users:

const aggregations = await prisma.user.aggregate({
  avg: {
    age: true,
  },
});

console.log("Average age:" + aggregations.avg.age);

Prisma Client supports the following aggregations:

  • avg (average)
  • sum (sum)
  • min (minimum value)
  • max (maximum value)

📚 Documentation: Aggregations

Preview features

New: Case insensitive filters (PostgreSQL only)

In 2.5.0 we introduce case insensitive filters for querying capabilities to Prisma Client. It allows you to query for fields in a case insensitive way.

Note: This feature will not work if you're using database collations that do not know how to convert between upper- and lowercase letters (e.g. the C collation).

📚 Documentation: Case sensitivity / Case-sensitive filtering

Feature flag

Insensitive filters querying needs to be enabled with the feature flag insensitiveFilters like so:

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

Usage

The new mode option you can pass to findMany influences the corresponding filter (e.g. contains or startsWith) but doesn't change the return type of the findMany query. mode can have two possible values:

  • default: Uses the default filter configured on the database level. If the collation is configured as case insensitive in the database, the default mode will be case insensitive as well. In that case, there's no need to use the insensitive mode.
  • insensitive: Uses the case insensitive filter (if possible).
const result = await prisma.user.findMany({
  where: {
    email: {
      equals: 'lowercase@UPPERCASE.com',
      mode: 'insensitive',
    },
  },
})

Please share your feedback on how this feature works for you. We are interested in both positive and negative feedback, so we know if this feature is already ready for production! (If encounter any problems, please open a new issue here).

Feature flags for middlewares, distinct and aggregationApi removed

As mentioned above, we were able to promote three features into this stable release. This was thanks to your help and feedback, so please keep trying the preview features if they're useful to you and help us by sharing feedback.

Already existing preview features from 2.1.0

Just a quick reminder:

  • In version 2.1.0 we introduced two experimental features, namely connectOrCreate and transactionApi.

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 client release

NewReleases is sending notifications on new releases.