Prisma: 2.3.0 Release

Release date:
July 21, 2020
Previous version:
2.2.2 (released July 13, 2020)
Magnitude:
2,797 Diff Delta
Contributors:
9 total committers
Data confidence:
Commits:

55 Commits in this Release

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

Authored July 15, 2020
Authored July 17, 2020
Authored July 16, 2020
Authored July 14, 2020
Authored July 15, 2020
Authored July 20, 2020
Authored July 16, 2020
Authored July 20, 2020
Authored July 21, 2020
Authored July 20, 2020
Authored July 21, 2020
Authored July 20, 2020
Authored July 21, 2020
Authored July 21, 2020
Authored July 16, 2020
Authored July 14, 2020
Authored July 21, 2020
Authored July 21, 2020
Authored July 15, 2020
Authored July 21, 2020
Authored July 14, 2020
Authored July 16, 2020

Top Contributors in 2.3.0

timsuchanek
Jolg42
madebysid
prisma-bot
renovate-bot
RafaelKr
pantharshit00
matthewmueller
dpetrick

Directory Browser for 2.3.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 issuing the 2.3.0 stable release.

Major improvements

Rename helper tool in VS Code Extension

The Prisma VS Code extension now helps you rename models, fields and enums:

<img src="https://user-images.githubusercontent.com/30771368/88035729-e1839b00-cb42-11ea-8c9d-039a2aaf8a61.gif" width="500px" />

Introspection uses order of columns in table to order fields in model

prisma introspect until recently ordered all fields in models alphabetically. Starting with 2.3.0 it now picks up the order from the columns in your database table and uses that same order for the fields in your models in your Prisma schema file.

Preview features

Renaming "Experimental features" to "Preview features"

With 2.1.0 we introduced feature flags for Prisma Client, called "Experimental Features". The property in the schema has been renamed from experimentalFeatures to previewFeatures to better communicate what they actually are.

generator client {
   provider             = "prisma-client-js"
-  experimentalFeatures = ["..."]
+  previewFeatures      = ["..."]
}

New: Distinct API

In 2.3.0 we introduce distinct querying capabilities to Prisma Client. It allows you to query for distinct (unique) rows of a model. In other words: The fields you provide in the distinct argument will be duplicate free.

πŸ“š Documentation: Distinct

Feature flag

Distinct querying needs to be enabled with the feature flag discintApi like so:

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

Usage

Distinct is only a filter and doesn't change the return type of the findMany query.

const result = await prisma.user.findMany({
  where: {},
  distinct: ['name']
})

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

New: Middlewares API

In 2.3.0 we introduce a Middlewares API as a preview feature. It allows you to hook into the control flow of Prisma Client.

πŸ“š Documentation: Middleware

Feature flag

Middlewares need to be enabled with the feature flag middlewares like so:

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

Usage

Here is an example that prints the execution time of a query made by Prisma Client:

const client = new PrismaClient()

client.use(async (params, next) => {
  console.log('params', params)
  const before = Date.now()
  const result = await next(params)
  const after = Date.now()
  console.log(`Query ${params.model}.${params.action} took ${after - before}ms`)
  return result
})

const data = await client.user.findMany({})

This will log the following:

params {
  args: {},
  dataPath: [],
  runInTransaction: false,
  action: 'findMany',
  model: 'User'
}

Query User.findMany took 2ms

Middlewares allow you to both manipulate the params and the result.

They are called in an "onion" fashion. If you have multiple middlewares, this is the order of things being called:

const client = new PrismaClient()

client.use(async (params, next) => {
  console.log('1')
  const result = await next(params)
  console.log('4')
  return result
})

client.use(async (params, next) => {
  console.log('2')
  const result = await next(params)
  console.log('3')
  return result
})

Prints: bash 1 2 3 4

While Prisma Client's middlewares work a bit different, they're by inspired Koa's middlewares.

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

Already existing preview features from 2.1.0 and 2.2.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 case they're useful for you, please give them a try and let us know! They stay in preview in this release.

Fixes and improvements

prisma

prisma-client-js

migrate

language-tools

studio

prisma-engines

Credits

Huge thanks to @RafaelKr for helping!