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`:
ts
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](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/working-with-json#filter-on-a-json-field)
<details><summary>Expand to view a Prisma schema for this example</summary>
A sample Prisma schema for the example above could look like this:
prisma
model Post {
id Int id default(autoincrement())
title String
content String?
jsonData Json
}
</details>
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"`).
bash
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](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/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](https://marketplace.visualstudio.com/items?itemName=Prisma.prisma) received an extraordinary number of tiny fixes this release, which will make using it much more pleasant. [Give it a try!](https://marketplace.visualstudio.com/items?itemName=Prisma.prisma)
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**](https://en.wikipedia.org/wiki/Feature_toggle) 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`](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/generators/) definition in their [Prisma schema](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema).
The `experimentalFeatures` field can be set like this:
prisma
generator client {
provider = "prisma-client-js"
experimentalFeatures = ["connectOrCreate", "transactionApi"]
}
Read more below to learn about the [`connectOrCreate`](https://github.com/prisma/prisma-client-js/issues/336) and [`transactionApi`](https://github.com/prisma/prisma-client-js/issues/667) 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`](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/relation-queries#update-an-existing-user-record-by-connect-it-to-two-existing-post-records-or-creating-two-new-post-records)
Example
In this example, we create a new post and _connect_ it to an author with the email address `alicehey.com`. If that author doesn't exist yet, create it with the name `"Alice"`.
ts
await prisma.post.create({
data: {
title: 'Prisma 2.1.0',
author: {
connectOrCreate: {
where: {
email: "alicehey.com"
},
create: {
name: "Alice",
email: "alicehey.com"
}
}
}
}
})
Feature flag
To enable `connectOrCreate`, you can use the feature flag `connectOrCreate` in your Prisma schema file:
prisma
generator client {
provider = "prisma-client-js"
experimentalFeatures = ["connectOrCreate"]
}
Please [share your feedback](https://github.com/prisma/prisma-client-js/issues/336) 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](https://github.com/prisma/prisma-client-js/issues/new/choose)).
`transactionApi`
While Prisma already ships transactions within [nested writes](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/relation-queries#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](https://github.com/prisma/prisma-client-js/issues/742)).
Example
ts
//run inside `async` function
await prisma.transaction([
prisma.user.create({
data: {
email: "aliceprisma.io",
},
}),
prisma.user.create({
data: {
email: "bobprisma.io",
},
}),
])
Alternatively, you can store the unresolved promises in variables and pass these to the new `transaction` function:
ts
const userOperation1 = prisma.user.create({
data: {
email: "aliceprisma.io",
},
})
const userOperation2 = prisma.user.create({
data: {
email: "bobprisma.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:
prisma
generator client {
provider = "prisma-client-js"
experimentalFeatures = ["transactionApi"]
}
Please leave feedback on how this feature works for you https://github.com/prisma/prisma-client-js/issues/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](https://github.com/prisma/prisma/issues/new/choose)).
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:
- [Custom names for relation fields](https://github.com/prisma/prisma/issues/2503)
- [`map` on models and enums](https://github.com/prisma/prisma/issues/2545)
- [`map` on fields and enum values](https://github.com/prisma/prisma/issues/2545)
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 https://github.com/prisma/prisma/issues/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](https://github.com/prisma/prisma/issues/new/choose)).
Fixes and improvements
`prisma`
- [Panic on a table that only has an ID, "called `Option::unwrap()` on a `None` value"](https://github.com/prisma/prisma/issues/1793)
- [.raw errors on date params w/ Postgres](https://github.com/prisma/prisma/issues/2533)
- [Improve error handling for incorrect raw parameters](https://github.com/prisma/prisma/issues/2561)
- [Parameter for `prisma init` to supply connection string to be used in `datasource`](https://github.com/prisma/prisma/issues/2577)
- [Configuration to disable update check and message](https://github.com/prisma/prisma/issues/2595)
- [queryRaw Error when calling SP or Function](https://github.com/prisma/prisma/issues/2679)
- [ENV var is required to execute `generate`/`validate`](https://github.com/prisma/prisma/issues/2686)
- [Tighten Version Check for P1 and P1.1 further](https://github.com/prisma/prisma/issues/2688)
- [Getting dbgenerated() for defaults on enums in Postgres](https://github.com/prisma/prisma/issues/2689)
- [`Environment variables loaded from` uses wrong directory separator (slashes) on Windows](https://github.com/prisma/prisma/issues/2699)
- [ENOENT when running prisma with pkg](https://github.com/prisma/prisma/issues/2717)
- [Statement caching for PostgreSQL](https://github.com/prisma/prisma/issues/2720)
- [CI Pipeline: Release stable release from chosen dev instead from current master state](https://github.com/prisma/prisma/issues/2724)
- [mixing uuid's with strings](https://github.com/prisma/prisma/issues/2784)
- [`prisma/debug` logs in tests](https://github.com/prisma/prisma/issues/2787)
- [Clean up `datasources` in Prisma Client constructor parameters](https://github.com/prisma/prisma/issues/2801)
`prisma-client-js`
- [create OR connect on nested writes (upsert)](https://github.com/prisma/prisma-client-js/issues/336)
- [Query batching & transactions support](https://github.com/prisma/prisma-client-js/issues/667)
- [Deeply nested creation never completes](https://github.com/prisma/prisma-client-js/issues/686)
- [Prisma DMMF `JsonFilter` input has no fields](https://github.com/prisma/prisma-client-js/issues/689)
- [Client, Engine version incorrect when overriding binary with Prisma client constructor](https://github.com/prisma/prisma-client-js/issues/696)
- [Adapt a more conflict resistant naming for Prisma client's types](https://github.com/prisma/prisma-client-js/issues/707)
- [JSON type throws error on certain types of valid JSON on `create` and `update`](https://github.com/prisma/prisma-client-js/issues/716)
- [Remove `__internal` from types](https://github.com/prisma/prisma-client-js/issues/729)
`vscode`
- [[Publishing] Send message to Slack channel on publish (success or failure)](https://github.com/prisma/vscode/issues/76)
- [Different README for unstable extension version](https://github.com/prisma/vscode/issues/119)
- [Notify Slack channel on extension publish](https://github.com/prisma/vscode/issues/160)
- [Trigger CI tests after bumping the version and before publishing](https://github.com/prisma/vscode/issues/197)
- [Remove `type_alias` from auto-completion ](https://github.com/prisma/vscode/issues/225)
- [Add auto-completion for env()](https://github.com/prisma/vscode/issues/226)
- [Cursor should stay inside [] for auto-completion](https://github.com/prisma/vscode/issues/228)
- [Autocompletion suggests block types after enum definition ](https://github.com/prisma/vscode/issues/231)
- [Auto-completion does not suggest block types when typing](https://github.com/prisma/vscode/issues/241)
- [Clean build before publish](https://github.com/prisma/vscode/issues/252)
- [Run integration tests on multiple platforms](https://github.com/prisma/vscode/issues/255)
- [Document "format on save" in READMEs](https://github.com/prisma/vscode/issues/259)
- [Add Prisma Version and Insider Version to Slack Notification Message](https://github.com/prisma/vscode/issues/260)
`studio`
- [Studio startup doesn't work (ENOENT)](https://github.com/prisma/studio/issues/415)
`prisma-engines`
- [Clarify CURRENT_TIMESTAMP support across MySQL versions](https://github.com/prisma/prisma-engines/issues/710)
- [Avoid relying on JSON database migrations backwards compatibility](https://github.com/prisma/prisma-engines/issues/741)
- [Introduce debugging mode to trigger panics in query engine](https://github.com/prisma/prisma-engines/issues/764)
- [Nested cursor-based pagination doesn't work as intended](https://github.com/prisma/prisma-engines/issues/768)
- [Move Windows build to GitHub Actions](https://github.com/prisma/prisma-engines/issues/811)