๐ **Help us spread the word about Prisma by starring the repo or [tweeting](https://twitter.com/intent/tweet?text=Check%20out%20the%20latest%20prisma%20release%20v4.3.0%20%F0%9F%9A%80%0D%0A%0D%0Ahttps://github.com/prisma/prisma/releases/tag/4.3.0) about the release.** ๐
Major improvements
Field reference support on query filters (Preview)
We're excited to announce [Preview](https://www.prisma.io/docs/about/prisma/releases#preview) support for field references. You can enable it with the `fieldReference` Preview feature flag.
Field references will allow you to compare columns against other columns. For example, given the following schema:
prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["fieldReference"]
}
model Invoice {
id Int id default(autoincrement)
paid Int
due Int
}
You can now compare one column with another after running `prisma generate`, for example:
ts
// Filter all invoices that haven't been paid yet
await prisma.invoice.findMany({
where: {
paid: {
lt: prisma.invoice.fields.due // paid < due
}
}
})
Learn more about field references in [our documentation](https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#compare-columns-in-the-same-table). Try it out and let us know what you think in this [GitHub issue](https://github.com/prisma/prisma/issues/15068).
Count by filtered relation (Preview)
In this release, we're adding support for the ability to count by a filtered relation. You can enable this feature by adding the `filteredRelationCount` Preview feature flag.
Given the following Prisma schema:
prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["filteredRelationCount"]
}
model User {
id Int id default(autoincrement())
email String unique
name String?
posts Post[]
}
model Post {
id Int id default(autoincrement())
title String
content String?
published Boolean default(false)
author User? relation(fields: [authorId], references: [id])
authorId Int?
}
You can now express the following query with the Preview feature after re-generating Prisma Client:
ts
// Count all user posts with the title "Hello!"
await prisma.user.findMany({
select: {
_count: {
select: {
posts: { where: { title: 'Hello!' } },
},
},
},
})
Learn more in [our documentation](https://www.prisma.io/docs/concepts/components/prisma-client/aggregation-grouping-summarizing#filter-the-relation-count) and let us know what you think in [this issue](https://github.com/prisma/prisma/issues/15069)
Multi-schema support (Preview)
In this release, we're adding _very_ early Preview support of multi-schema support for [PostgreSQL](https://www.postgresql.org/docs/14/ddl-schemas.html) and [SQL Server](https://docs.microsoft.com/en-us/sql/relational-databases/security/authentication-access/create-a-database-schema?view=sql-server-ver16) behind the `multiSchema` Preview feature flag. With it, you can write a Prisma schema that accesses models across multiple schemas.
Read further in this [GitHub issue](https://github.com/prisma/prisma/issues/1122#issuecomment-1231773471). Try it out and let us know what you think in this [GitHub issue](https://github.com/prisma/prisma/issues/15077).
Prisma CLI exit code fixes
We've made several improvements to the Prisma CLI:
- `prisma migrate dev` previously returned a successful exit code (0) when `prisma db seed` was triggered but failed due to an error. We've fixed this and `prisma migrate dev` will now exit with an unsuccessful exit code (1) when seeding fails.
- `prisma migrate status` previously returned a successful exit code (0) in unexpected cases. The command will now exit with an unsuccessful exit code (1) if:
- An error occurs
- There's a failed or unapplied migration
- The migration history diverges from the local migration history (`/prisma/migrations` folder)
- Prisma Migrate does not manage the database' migration history
- The previous behavior when canceling a prompt by pressing <kbd>Ctrl</kbd> + <kbd>C</kbd> was returning a successful exit code (0). It now returns a non-successful, `SIGINT`, exit code (130).
- In the _rare_ event of a Rust panic from the Prisma engine, the CLI now asks you to submit an error report and exit the process with a non-successful exit code (1). Prisma previously ended the process with a successful exit code (0).
Improved precision for the `tracing` Preview feature
Before this release, you may have occasionally seen some traces that took 0ฮผs working with the `tracing` Preview feature. In this release, we've increased the precision to ensure you get accurate traces.
Let us know if you run into any issues in this [GitHub issue](https://github.com/prisma/prisma/issues/14640).
`prisma format` now uses a Wasm module
Initially, the `prisma format` command relied on logic from the Prisma engines in form of a native binary. In an ongoing effort to make `prisma` more portable and easier to maintain, we decided to shift to a Wasm module.
`prisma format` now uses the same Wasm module as the one the Prisma language server uses, i.e. `prisma/prisma-fmt-wasm`, which is now visible in `prisma version` command's output.
Let us know what you think. In case you run into any issues, let us know by creating a [GitHub issue](https://github.com/prisma/prisma).
MongoDB query fixes
> โ ๏ธย This may affect your query results if you relied on this _buggy_ behavior in your application.
While implementing field reference support, we noticed a few correctness bugs in our MongoDB connector that we fixed along the way:
1. `mode: insensitive` alphanumeric comparisons (e.g. โaโ > โZโ) didnโt work ([GitHub issue](https://github.com/prisma/prisma/issues/14663))
2. `mode: insensitive` didnโt exclude undefined ([GitHub issue](https://github.com/prisma/prisma/issues/14664))
3. `isEmpty: false` on lists types (e.g. String[]) returned true when a list is empty ([GitHub issue](https://github.com/prisma/prisma-engines/issues/3133))
4. `hasEvery` on list types wasnโt aligned with the SQL implementations ([GitHub issue](https://github.com/prisma/prisma-engines/issues/3132))
JSON filter query fixes
> โ ๏ธย This may affect your query results if you relied on this _buggy_ behavior in your application.
We also noticed a few correctness bugs in when filtering JSON values when used in combination with the `NOT` condition. For example:
ts
await prisma.log.findMany({
where: {
NOT: {
meta: {
string_contains: "GET"
}
}
}
})
<details>
<summary>Prisma schema</summary>
prisma
model Log {
id Int id default(autoincrement())
level Level
message String
meta Json
}
enum Level {
Info
Warn
Error
}
</details>
If you used `NOT` with any of the following queries on a `Json` field, double-check your queries to ensure they're returning the correct data:
- `string_contains`
- `string_starts_with`
- `string_ends_with`
- `array_contains`
- `array_starts_with`
- `array_ends_with`
- `gt`/`gte`/`lt`/`lte`
Prisma extension for VS Code improvements
The Prisma language server now provides [Symbols](https://code.visualstudio.com/docs/editor/editingevolved#_go-to-symbol) in VS Code. This means you can now:
- See the different blocks (`datasource`, `generator`, `model`, `enum`, and `type`) of your Prisma schema in the [Outline view](https://code.visualstudio.com/docs/getstarted/userinterface#_outline-view). This makes it easier to navigate to a block in 1 click
A few things to note about the improvement are that:
- <kbd>CMD</kbd> + hover on a field whose type is an enum will show the block in a popup
- <kbd>CMD</kbd> + left click on a field whose type is a model or enum will take you to its definition.
<img alt="" src="https://user-images.githubusercontent.com/33921841/187421410-cd1f30cf-d0b4-4147-9467-70ca4da12321.png">
- Enable [Editor sticky scroll](https://code.visualstudio.com/updates/v1_70#_editor-sticky-scroll) from version `1.70` of VS Code. This means you can have sticky blocks in your Prisma schema, improving your experience when working with big schema files
Make sure to update your VS Code application to 1.70, and the [Prisma extension](https://marketplace.visualstudio.com/items?itemName=Prisma.prisma) to `4.3.0`.
We'd also like to give a big **Thank you** to yume-chan for your [contribution](https://github.com/yume-chan)!
Prisma Studio improvements
We've made several improvements to the filter panel which includes:
- Refined filter panel
- Reducing the contrast of the panel in dark mode
- Ability to toggle filters in the panel
- Refined error handling for MongoDB m-n relations
Prisma Studio prevents fatal errors when interacting with m-n relations by explicitly disabling creating, deleting, or editing records for m-n relations
- Multi-row copying
You can select multiple rows and copy them to your clipboard as JSON objects using <kbd>CMD</kbd> + <kbd>C</kbd> on MacOS or <kbd>Ctrl</kbd> + <kbd>C</kbd> on Windows/ Linux
Prisma Client Extensions: request for comments
For the last couple of months, we've been working on a specification for an upcoming feature โ Prisma Client extensions. We're now ready to share our proposed design and we would appreciate your feedback.
Prisma Client Extensions aims to provide a type-safe way to extend your existing Prisma Client instance. With Prisma Client Extensions you can:
- Define computed fields
- Define methods for your models
- Extend your queries
- Exclude fields from a model
... and much more!
Hereโs a glimpse at how that will look:
jsx
const prisma = new PrismaClient().$extend({
$result: {
User: {
fullName: (user) => {
return `${user.firstName} ${user.lastName}`
},
},
},
$model: {
User: {
signup: async ({ firstName, lastName, email, password }) => {
// validate and create the user here
return prisma.user.create({
data: { firstName, lastName, email, password }
})
},
},
},
})
const user = await prisma.user.signup({
firstName: "Alice",
lastName: "Lemon",
email: "aliceprisma.io",
password: "pri$mar0ckz"
})
console.log(user.fullName) // Alice Lemon
For further details, refer to [this GitHub issue](https://github.com/prisma/prisma/issues/15074). Have a read and let us know what you think!
Fixes and improvements
Prisma Client
- [Allow WHERE conditions to compare columns in same table](https://github.com/prisma/prisma/issues/5048)
- [Dates serialized without quotation marks in query event parameters property ](https://github.com/prisma/prisma/issues/6578)
- [Ability to filter count in "Count Relation Feature"](https://github.com/prisma/prisma/issues/8413)
- [Some traces show 0ฮผs](https://github.com/prisma/prisma/issues/14614)
- [[MongoDB] Alphanumeric insensitive filters don't work](https://github.com/prisma/prisma/issues/14663)
- [[MongoDB] Insensitive filters don't exclude undefineds](https://github.com/prisma/prisma/issues/14664)
- [Schema size affects runtime speed](https://github.com/prisma/prisma/issues/14695)
- [Prisma Client always receive engine spans even when not tracing](https://github.com/prisma/prisma/issues/14842)
- [Environment variables not available when using Wrangler 2](https://github.com/prisma/prisma/issues/14924)
Prisma
- [Undo "skip flaky referentialActions sql server test"](https://github.com/prisma/prisma/issues/7936)
- [Add `prisma/prisma-fmt-wasm` to CLI and output dependency version in `-v`, use instead of Formatter Engine binary](https://github.com/prisma/prisma/issues/12496)
- [Add jest snapshots for improved `db push` output in MongoDB](https://github.com/prisma/prisma/issues/13776)
- [OpenSSL error message appearing while using query-engine has false positives](https://github.com/prisma/prisma/issues/14104)
- [Calling `dmmf` raises "Schema parsing - Error while interacting with query-engine-node-api library" misleading error message when there is a schema validation error.](https://github.com/prisma/prisma/issues/14588)
- [Unique composite indexes do not clash with a matching name on schema validation (composite types)](https://github.com/prisma/prisma/issues/14768)
- [CLI: `migrate status` should return a non-successful exit code (1) when a failed migration is found or an error occurs](https://github.com/prisma/prisma/issues/14860)
- [CLI: `migrate dev` should return a non-successful exit code (1) when there is an error during seeding](https://github.com/prisma/prisma/issues/14862)
Prisma Migrate
- [Prisma CLI non-interactive detection is incorrect.](https://github.com/prisma/prisma/issues/14620)
Language tools (e.g. VS Code)
- [Provide Symbols to VSCode](https://github.com/prisma/language-tools/issues/751)
- [Support "Outline view" for Prisma Schema](https://github.com/prisma/language-tools/issues/1031)
Credits
Huge thanks to abenhamdine, drzamich, AndrewSouthpaw, kt3k, lodi-g, Gnucki, apriil15, givensuman for helping!
Prisma Data Platform
We're working on the Prisma Data Platform โ a collaborative environment for connecting apps to databases. It includes the:
- **Data Browser** for navigating, editing, and querying data
- **Data Proxy** for your database's persistent, reliable, and scalable connection pooling.
- **Query Console** for experimenting with queries
[Try it out](https://cloud.prisma.io/) and let us know what you think!
๐ผ We're hiring!
If you're interested in joining our growing team to help empower developers to build data-intensive applications, Prisma is the place for you.
We're looking for a [Developer Advocate (Frontend / Fullstack)](https://grnh.se/894b275b2us) and [Back-end Engineer: Prisma Data Platform](https://grnh.se/45afe7982us).
Feel free to read the job descriptions and apply using the links provided.
๐บ Join us for another "What's new in Prisma" livestream
Learn about the latest release and other news from the Prisma community by joining us for another ["What's new in Prisma"](https://youtu.be/YE668p2nxv8) livestream.
The stream takes place [on YouTube](https://youtu.be/YE668p2nxv8) on **Thursday, September 1** at **5 pm Berlin | 8 am San Francisco**.