github prisma/prisma 2.1.0

latest releases: 5.11.0, 5.10.2, 5.10.1...
3 years ago

Today, we are issuing the 2.1.0 stable release.

Major improvements

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

Basic filtering on Json data in Prisma Client

When querying data, you can now perform basic filtering with Json fields using equal and not:

const jsonData = [
  {
    array1key: 'array1value',
  },
]

// `equal` filter. Return all posts with this particular `jsonData`
const result = await prisma.post.findMany({
  where: {
    jsonData
  },
})


// `not` filter. Return all posts, which don't have this `jsonData`
const result = await prisma.post.findMany({
  where: {
    jsonData: { not: jsonData }
  },
})

📚 Documentation: Working with Json fields

Expand to view a Prisma schema for this example

A sample Prisma schema for the example above could look like this:

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  jsonData  Json
}

Hide the Prisma CLI update message

You can now hide the Prisma CLI update notifier message by setting the environment variable PRISMA_HIDE_UPDATE_MESSAGE (e.g. to "1", "true" or "asd").

export PRISMA_HIDE_UPDATE_MESSAGE="1"

Prepared statement caching for PostgreSQL

Under the hood, we enabled prepared statement caching for PostgreSQL. This way Prisma Client's query engine does not repeatedly prepare the same statement but can reuse an existing one which reduces database CPU usage and query latency.

Many bug fixes for Prisma VSCode Extension

The Prisma VSCode extension received an extraordinary number of tiny fixes this release, which will make using it much more pleasant. Give it a try!

Experimental features

With the GA release of Prisma 2.0, you can expect much more stable releases in the future. At the same time, we of course want to be able to release new features that are fresh from our developers for you to try out. This is the best way we can get them stable enough to be generally available.

We are doing this with experimental features.

🚨 The following features are not part of our official and stable API and may be changed or removed completely in a future release.

Enabling experimental features in Prisma Client

With this release, we introduce feature flags for Prisma Client. Similar to the --experimental flag in the CLI (for prisma studio and prisma migrate), this enables us to hide functionality from the default API that all users get when installing Prisma and Prisma Client. Instead, users can explicitly opt-in to certain features by enabling them via the new experimentalFeatures field on the Prisma Client generator definition in their Prisma schema.

The experimentalFeatures field can be set like this:

generator client {
  provider = "prisma-client-js"
  experimentalFeatures = ["connectOrCreate", "transactionApi"]
}

Read more below to learn about the connectOrCreate and transactionApi experimental features.

connectOrCreate

When updating or creating a record, we now provide a new operation as a nested mutation: connectOrCreate.
You can connect (if exists) or create (if it doesn't exist) to a related row.

📚 Documentation: Relation queries: connectOrCreate

Example

In this example, we create a new post and connect it to an author with the email address alice@hey.com. If that author doesn't exist yet, create it with the name "Alice".

await prisma.post.create({
  data: {
    title: 'Prisma 2.1.0',
    author: {
      connectOrCreate: {
        where: {
          email: "alice@hey.com"
        },
        create: {
          name: "Alice",
          email: "alice@hey.com"
        }
      }
    }
  }
})

Feature flag

To enable connectOrCreate, you can use the feature flag connectOrCreate in your Prisma schema file:

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

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

transactionApi

While Prisma already ships transactions within nested writes, there are many use cases, where you might want to perform multiple unrelated write operations in a transaction and rollback, if one of them fails. By wrapping your write operations in the new transaction() function, you can achieve exactly this!

(Note, that these transactions are not long-running and are executed directly after each other. This is an explicit design decision of Prisma. In case this does not cover your use case yet, please chime in on GitHub).

Example

//run inside `async` function
await prisma.transaction([
  prisma.user.create({
    data: {
      email: "alice@prisma.io",
    },
  }),
  prisma.user.create({
    data: {
      email: "bob@prisma.io",
    },
  }),
])

Alternatively, you can store the unresolved promises in variables and pass these to the new transaction function:

const userOperation1 = prisma.user.create({
  data: {
    email: "alice@prisma.io",
  },
})

const userOperation2 = prisma.user.create({
  data: {
    email: "bob@prisma.io",
  },
})


//run inside `async` function
await prisma.transaction([userOperation1, userOperation2])

Feature flag

To enable the experimental transaction api, you can use the feature flag transactionApi in your Prisma schema file:

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

Please leave feedback on how this feature works for you prisma/prisma-client-js#667. We are interested in both positive and negative feedback, so we know if this feature is already ready for production. (If there are problems you can also open a new issue here).

Enabling experimental features in the Prisma CLI

In the Prisma CLI, we are using dedicated experimental flags that can be added to any command.

Re-Introspection

One common problem when using Prisma is that manual changes to your Prisma schema are overwritten the next time you run prisma introspect. This version adds an experimental mode for this functionality where we try to keep some of these changes:

You enable this by supplying the --experimental-reintrospection flag to prisma introspect:

npx prisma introspect --experimental-reintrospection

Please leave feedback on how this feature works for you #2829. We are interested in both positive and negative feedback, so we know if this feature is already ready for production. (If there are problems you can also open a new issue at here).

Fixes and improvements

prisma

prisma-client-js

vscode

studio

prisma-engines

Don't miss a new prisma release

NewReleases is sending notifications on new releases.