Skip to content

2.5.0

Compare
Choose a tag to compare
@Jolg42 Jolg42 released this 18 Aug 16:39

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
  • aggregateApi

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", "aggregateApi"]
}

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