yarn @prisma/client 2.3.0

latest releases: 5.23.0-dev.7, 5.23.0-dev.6, 5.23.0-dev.5...
4 years ago

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:

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:

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!

Don't miss a new client release

NewReleases is sending notifications on new releases.