December 29, 2022

What's new in Prisma? (Q4/22)

Here’s all you need to know about the Prisma ecosystem and community from August to December 2022.

What's new in Prisma? (Q4/22)

Overview

Releases & new features

Our engineers have been working hard, issuing new releases with many improvements and new features. Here is an overview of what we've launched lately.

You can stay up-to-date about all upcoming features on our roadmap.

Features now in General Availability

Interactive transactions

Interactive transactions allow you to pass an async function into a $transaction, and execute any code you like between the individual Prisma Client queries. Once the application reaches the end of the function, the transaction is committed to the database. If your application encounters an error as the transaction is being executed, the function will throw an exception and automatically rollback the transaction.

Here are some of the feature highlights we've built:

Here's an example of an interactive transaction with a Serializable isolation level:

You can now remove the interactiveTransactions Preview feature in your schema.

Relation mode

relationMode="prisma" is now stable for our users working with databases that don't rely on foreign keys to manage relations. 🎉

Prisma’s relation mode started as a way to support PlanetScale which does not allow you to create foreign keys for better online migration support. We transformed that into our Referential Integrity Emulation in 3.1.1 when we realised that more users could benefit from it, and then integrated it as the default mode for MongoDB, which generally does not have foreign keys. Prisma needed to use emulation to give the same guarantees.

We then realized the feature was more than just referential integrity and affected how relations work. To reflect this, we renamed the feature to relation mode and the datasource property to relationMode in 4.5.0

Index warnings for relationMode = "prisma"

We've added a warning to our Prisma schema validation that informs you that the lack of foreign keys might result in slower performance — and that you should add an @@index manually to your schema to counter that. This ensures your queries are equally fast in relation mode prisma as they are with foreign keys.

With relationMode = "prisma", no foreign keys are used, so relation fields will not benefit from the index usually created by the relational database under the hood. This can lead to slower performance when querying these fields. We recommend manually adding an index.

We also added a fix to our VS Code extension to help adding the suggested index with minimal effort:

https://user-images.githubusercontent.com/33921841/204537961-fb1049d3-ca33-4055-8e8e-0f6448e09695.png

To get started, make the following changes to your schema:

For more information, check out our updated relation mode documentation.

New Preview features

Prisma Client improvements

  • extendedWhereUnique improvements ––– in 4.5.0, we introduced this Preview feature to allow filtering for non-unique properties in unique where queries. We added new rules to decide when concurrent findUnique queries get batched into a findMany query. Let us know your thoughts and share your feedback on the Preview feature in this GitHub issue.
  • fieldReference ––– field references support on query filters will allow you to compare columns against other columns. To enable column comparisons in the same table, add the fieldReference feature flag to the generator block of your Prisma Schema. Try it out and let us know what you think in this GitHub issue.
  • filteredRelationCount ––– we've added support for the ability to count by a filtered relation. You can enable this feature by adding the filteredRelationCount Preview feature flag. Learn more in our documentation and let us know what you think in this issue.
  • Deno for Prisma Client for Data Proxy ––– we have released initial support for this feature in collaboration with the amazing team at Deno 🦕. To use Prisma Client in a Deno project, add the deno Preview feature flag to your Prisma schema and define a folder as output (this is required for Deno). Read this guide in our documentation for a full example and individual steps. For feedback, please comment on this GitHub issue.

Prisma Client extensions

We’ve added Preview support for Prisma Client Extensions. This feature introduces new capabilities to customize and extend Prisma Client. We have opened up four areas for extending Prisma Client:

Read about how Prisma Client just became a lot more flexible and watch a demo here:

We're excited to see what you build with them! For more information, check out our docs and let us know what you think in this GitHub issue.

Multi-schema support for CockroachDB and PostgreSQL

The ability to query and manage multiple database schemas has been a long-standing feature request from our community. We've now added Preview support for multi-schema for CockroachDB and PostgreSQL. 🎉 We’ve added support for:

  • Introspecting databases that organize objects in multiple database schemas
  • Managing multi-schema database setups directly from Prisma schema
  • Generating migrations that are database schema-aware with Prisma Migrate
  • Querying across multiple database schemas with Prisma Client If you already have a CockroachDB or a PostgreSQL database using multiple schemas, you can quickly get up and running set up multiple schemas by:
  • Enabling the Preview feature in the Prisma schema
  • Defining the schemas in the schemas property in the datasource block
  • Introspecting your database using prisma db pull

You can further evolve your database schema using the multi-schema Preview feature by using prisma migrate dev. For further details, refer to our documentation and let us know what you think in this GitHub issue.

PostgreSQL extension management

We’ve added support for declaring PostgreSQL extensions in the Prisma schema. The feature comes with support for introspection and migrations. You can now adopt, evolve and manage which PostgreSQL database extensions are installed directly from within your Prisma schema.

💡 This feature adds support to manage PostgreSQL extensions in Prisma schema. It does not provide additional query capabilities and datatypes in Prisma Client.

To try this feature, enable the Preview feature flag and then you will be able to use the new extensions property in the datasource block of your Prisma schema.

⚠️ To avoid noise from introspection, we currently only introspect the following allow-list: citext, pgcrypto, uuid-ossp, and postgis. But you can add and configure any extension to your Prisma schema manually.

Please visit our documentation to learn more about this feature or leave a comment with feedback on the GitHub issue.

Prisma Client tracing support

Tracing allows you to track requests as they flow through your application. This is especially useful for debugging distributed systems where each request can span multiple services.

With tracing, you can now see how long Prisma takes and what queries are issued in each operation. You can visualize these traces as waterfall diagrams using tools such as JaegerHoneycomb, or DataDog.

https://user-images.githubusercontent.com/33921841/183606710-5945999c-4e0b-420c-9de5-4c6bf9984f0c.png

Read more about tracing in our announcement post and learn more in our documentation on how to start working with tracing.

Try it out and let us know what you think.

General improvements

Improved serverless experience with smaller engines size

We have decreased the size of our engine files by an average of 50%. The size of the Query Engine used on Debian, with OpenSSL 3.0.x, for example, went from 39MB to 14MB.

Additionally, we have started optimizing how the Prisma schema is loaded in Prisma Client. You should notice a considerable improvement when executing the first query if you're working with a bigger schema with many models and relations. Read more about it in the 4.8.0 release notes.

Improved OpenSSL 3.x support

Prisma now supports OpenSSL 3 builds for Linux Alpine on x86_64 architectures. This particularly impacts users running Prisma on node:alpine and node:lts-alpine Docker images. You can read more details about it in this GitHub comment.

We also have rewritten our OpenSSL version detection logic, making it future-proof. We now expect Prisma to support systems running with any OpenSSL 3 minor versions out of the box.

Native database level upserts for PostgreSQL, SQLite, and CockroachDB

Prisma’s upsert is one of its most powerful and most convenient APIs. Prisma will now default to the native database upsert for PostgreSQL, SQLite, and CockroachDB whenever possible.

Get more details in the 4.6.0 release notes and try it out. If you run into any issues, don't hesitate to create a GitHub issue.

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 Ctrl + C 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).

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. After the 4.3.0 release, prisma format will be using 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, create a GitHub issue.

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)
  2. mode: insensitive didn’t exclude undefined (GitHub issue)
  3. isEmpty: false on lists types (e.g. String[]) returned true when a list is empty (GitHub issue)
  4. hasEvery on list types wasn’t aligned with the SQL implementations (GitHub issue)

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 when filtering JSON values, when used in combination with the NOT condition. For example:

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 in VS Code. This means you can now:

  • See the different blocks (datasourcegeneratormodelenum, and type) of your Prisma schema in the Outline view. This makes it easier to navigate to a block in 1 clickA few things to note about the improvement are that:

    • CMD + hover on a field whose type is an enum will show the block in a popup
    • CMD + left click on a field whose type is a model or enum will take you to its definition.

    https://user-images.githubusercontent.com/33921841/187421410-cd1f30cf-d0b4-4147-9467-70ca4da12321.png

  • Enable 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 to 4.3.0.

Renaming of Prisma Client metrics

We've renamed the metrics — counters, gauges, and histograms — returned from prisma.$metrics() to make it a little easier to understand at a glance.

PreviousUpdated
query_total_operationsprisma_client_queries_total
query_total_queriesprisma_datasource_queries_total
query_active_transactionsprisma_client_queries_active
query_total_elapsed_time_msprisma_client_queries_duration_histogram_ms
pool_wait_duration_msprisma_client_queries_wait_histogram_ms
pool_active_connectionsprisma_pool_connections_open
pool_idle_connectionsprisma_pool_connections_idle
pool_wait_countprisma_client_queries_wait

Give Prisma Client metrics a shot and let us know what you think in this GitHub issue

To learn more, check out our documentation.

Syntax highlighting for raw queries in Prisma Client

We’ve added syntax highlighting support for raw SQL queries when using $queryRaw```  and $executeRaw``` . This is made possible using Prisma's VS Code extension.

https://user-images.githubusercontent.com/33921841/183627500-ad866a4d-8624-4f05-839f-81daaaf3ce2d.png

Note: Syntax highlighting currently doesn't work with when using parentheses, ()$queryRaw()$executeRaw()$queryRawUnsafe(), and $executeRawUnsafe().

If you are interested in having this supported, let us know in this GitHub issue.

Experimental Cloudflare Module Worker support

We fixed a bug that prevented the Prisma Edge Client from working with Cloudflare Module Workers. We now provide experimental support with a workaround for environment variables.

Try it out and let us know how what you think! In case you run into any errors, feel free to create a bug report.

Fixed “Invalid string length” error in Prisma Studio and Prisma Data Platform Data Browser

Many people were having issues with an "Invalid string length" error both in Prisma Studio and Prisma Data Platform Data Browser. This issue can be resolved through this workaround. The root cause of this issue was fixed and it should not occur again.

New P2034 error code for transaction conflicts or deadlocks

When using certain isolation levels, it is expected that a transaction can fail due to a write conflict or a deadlock, throwing an error. One way to solve these cases is by retrying the transaction.

To make this easier, we're introducing a new PrismaClientKnownRequestError with the error code P2034: "Transaction failed due to a write conflict or a deadlock. Please retry your transaction". You can programmatically catch the error and retry the transaction. Check out the 4.4.0 release notes for further details here and examples.

Community

We wouldn't be where we are today without our amazing community of developers. Our Slack has almost 50k members and is a great place to ask questions, share feedback and initiate discussions around Prisma.


Join Slack

Meetups

TypeScript Berlin #10
TypeScript Berlin #10

Time for the framework-agnostic app has come? - Ema Suriano

Fullstack Type Safety (Remix Edition) - Alex Ruheni

Module-Federation: A game-changer in JavaScript architecture - Vitor Alencar

Rust and Tell - EuroRust B-Sides
Rust and Tell - EuroRust B-Sides

Case study: Rust in axle OS - Philip Tennen

Let our rusty crab 🦀 explore the depths of the C 🌊 - Yvan Sraka

Do not break GraphQL, extend it! - Michal Rosteck

GraphQL Berlin #26
GraphQL Berlin #26

Are you using GraphQL the intended way? - Laurin Quast (The Guild)

The future of GraphQL IDEs - Rikki Schult (GraphQL Foundation) and Thomas Heyenbrock (Stellate)

Do not break GraphQL, extend it! - Paolo Insogna (NearForm)

Rust and Tell — BBQ Edition
Rust and Tell — BBQ Edition

Hot code reload in Rust - Robert K

Using Rust inside Scala with "robusta_jni" - Bogdan K

TypeScript Berlin #9
TypeScript Berlin #9

Type Guards and how they can improve your code quality - Benny Neugebauer (South Pole)

How to make sure types are not lying to you? - Fabien Bernard (Xata)

Introduction to Data Modeling with Algebraic Data Types in TypeScript with Alge - Jason Kuhrt (Prisma)

try-prisma CLI

try-prisma is a CLI tool that helps you easily get up and running with any project in the prisma/prisma-examples repository.

The easiest way to set up a project using try-prisma is to run the following command:

Read more on Try Prisma: The Fastest Way to Explore Prisma Examples.

Design partner program

Are you building data-intensive applications in serverless environments using Prisma? If so, you should join our Design Partner Program to help us build the tools that best fit your workflows!

The Design Partner Program aims to help development teams solve operational, data-related challenges in serverless environments. Specifically, we’re looking to build tools that help with the following problems:

  • Solutions to listen and react to database changes in real time are either brittle or too complex to build and operate.
  • Coordinating workflows executed via a set of isolated functions or services spreads that coordination logic across these services instead of keeping it centralized and maintainable. This adds unnecessary overhead and clutter to your business logic.
  • Optimizing the data access layer for scaling performance often involves projecting data into denormalized views, or caching. These methods come with complex logic to figure out strategies for cache invalidation or preventing to use stale data.
  • Building web applications on modern Serverless platforms such as Vercel or Netlify often breaks down as soon as you need to execute on any of the topics listed above. This pushes to re-platform on a traditional infrastructure, delaying projects, and losing productivity benefits offered by Vercel or Netlify.

Submit an application through our application form.

Videos, livestreams & more

What’s new in Prisma

Every other Thursday, our developer advocates, Nikolas BurkAlex RuheniTasin IshmamSabin Adams, and Stephen King, discuss the latest Prisma release and other news from the Prisma ecosystem and community. If you want to travel back in time and learn about a past release, you can find all of the shows from this quarter here:

Videos

We published several videos this quarter on our YouTube channel. Check them out, and subscribe to not miss out on future videos.

Written content

We published several articles on our blog this quarter:

We also published several technical articles on the Data Guide that you might find useful:

We’re hiring

Also, we're hiring for various roles! If you're interested in joining us, check out our jobs page.


Explore Jobs


What’s next?

The best places to stay up-to-date about what we are currently working on are our GitHub issues and our public roadmap.

You can also engage in conversations in our Slack channel and start a discussion on GitHub or join one of the many Prisma meetups around the world.

Don’t miss the next post!

Sign up for the Prisma Newsletter