yarn @prisma/client 2.2.0

latest releases: 5.21.0-integration-itx-refactor.13, 5.21.0-integration-itx-refactor.12, 5.21.0-integration-engines-5-21-0-20-integration-itx-refactor-4c3d81888c1061f682f4be20a2dafa2126e6af1f.2...
4 years ago

Today, we are issuing the 2.2.0 stable release.

Major improvements

Next to a lot of bug fixes, this version includes a number of new features!

Quick fix suggestions in Prisma VSCode Extension

The Prisma VS Code extension now helps you fix any accidental typos and offers more convenient "Quick Fixes" right inside your editor.

Make datasource provider dynamic via environment variables

The provider field on the datasource defininitions in your Prisma schema now also accepts an array of strings (instead of just a plain string). This can be helpful when you want to switch environments which point to different databases based on an environment variable. Learn more about this feature here.

datasource db {
  provider = ["sqlite", "postgres"]
  url      = env("DATABASE_URL")
}

Experimental features

Already existing experimental features

Just a quick reminder: In v2.1.0 we introduced two experimental features, namely connectOrCreate and transactionApi. In case they're useful for you, please give them a try! They stay experimental in this release.

Re-Introspection

We were able to continue to improve the re-introspection flow based on your feedback. Thanks!

Aggregations API

While Prisma Client already provides a count query for each model, we now introduce further aggregation functionality for number fields.

If your model has a field of type Int or Float, the following aggregations will be available:

  • sum: Sum up all values of a field for the selected rows.
  • min: Get the minimum value for a field for the selected rows.
  • max: Get the maximum value for a field for the selected rows.
  • avg: Get the average value for a field for the selected rows.

Example

Note, that the count API is always available, while sum, min, max, and avg are only available for a model if it has a number field.

Prisma Schema Prisma Client Query
Result
model User {
  id   Int @id
  age  Int
  name String
}
const result = await prisma.user.aggregate({
  where: { age: { gt: 5 } }, // optional
  count: true,
  avg: {
    age: true,
  },
  max: {
    age: true,
  },
  min: {
    age: true,
  },
  sum: {
    age: true
  }
})
{
  "count": 10,
  "avg": {
    "age": 80
  },
  "max": {
    "age": 163
  },
  "min": {
    "age": 5
  },
  "sum": {
    "age": 800
  }
}

Feature flag

In order to enable this experimental feature, note that you need to set the feature flag aggregateApi in the Prisma Client generator block in your schema:

generator client {
  provider = "prisma-client-js"
  experimentalFeatures = ["aggregateApi"]
}

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).

Fixes and improvements

prisma

prisma-client-js

migrate

vscode

studio

prisma-engines

Don't miss a new client release

NewReleases is sending notifications on new releases.