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 A sample Prisma schema for the example above could look like this:
Json
fields
Expand to view a Prisma schema for this example
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
- Panic on a table that only has an ID, "called
Option::unwrap()
on aNone
value" - .raw errors on date params w/ Postgres
- Improve error handling for incorrect raw parameters
- Parameter for
prisma init
to supply connection string to be used indatasource
- Configuration to disable update check and message
- queryRaw Error when calling SP or Function
- ENV var is required to execute
generate
/validate
- Tighten Version Check for P1 and P1.1 further
- Getting dbgenerated() for defaults on enums in Postgres
Environment variables loaded from
uses wrong directory separator (slashes) on Windows- ENOENT when running prisma with pkg
- Statement caching for PostgreSQL
- CI Pipeline: Release stable release from chosen dev instead from current master state
- mixing uuid's with strings
@prisma/debug
logs in tests- Clean up
datasources
in Prisma Client constructor parameters
prisma-client-js
- create OR connect on nested writes (upsert)
- Query batching & transactions support
- Deeply nested creation never completes
- Prisma DMMF
JsonFilter
input has no fields - Client, Engine version incorrect when overriding binary with Prisma client constructor
- Adapt a more conflict resistant naming for Prisma client's types
- JSON type throws error on certain types of valid JSON on
create
andupdate
- Remove
__internal
from types
vscode
- [Publishing] Send message to Slack channel on publish (success or failure)
- Different README for unstable extension version
- Notify Slack channel on extension publish
- Trigger CI tests after bumping the version and before publishing
- Remove
type_alias
from auto-completion - Add auto-completion for env()
- Cursor should stay inside [] for auto-completion
- Autocompletion suggests block types after enum definition
- Auto-completion does not suggest block types when typing
- Clean build before publish
- Run integration tests on multiple platforms
- Document "format on save" in READMEs
- Add Prisma Version and Insider Version to Slack Notification Message