apps/blog/content/blog/wnip-q4-2022-f66prwkjx72s/index.mdx
Here’s all you need to know about the Prisma ecosystem and community from August to December 2022.
prisma format now uses a Wasm moduleP2034 error code for transaction conflicts or deadlocksOur 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.
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:
4.2.04.6.0Here's an example of an interactive transaction with a Serializable isolation level:
await prisma.$transaction(
async (prisma) => {
// Your transaction...
},
{
isolationLevel: Prisma.TransactionIsolationLevel.Serializable,
maxWait: 5000,
timeout: 10000,
}
)
You can now remove the interactiveTransactions Preview feature in your schema.
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
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:
To get started, make the following changes to your schema:
diff
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
- referentialIntegrity = "prisma"
+ relationMode = "prisma"
}
generator client {
provider = "prisma-client-js"
- previewFeatures = ["referentialIntegrity"]
}
For more information, check out our updated relation mode documentation.
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 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.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:
model: add custom methods or fields to your modelsclient: add client-level methods to Prisma Clientresult: add custom fields to your query resultsquery: create custom Prisma Client queriesRead about how Prisma Client just became a lot more flexible and watch a demo here:
<Youtube videoId="oWjqeU7fowE?t=718" />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.
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:
schemas property in the datasource blockprisma db pullYou 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.
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.
generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [hstore(schema: "myHstoreSchema"), pg_tgrm, postgis(version: "2.1")]
}
⚠️ 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.
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 Jaeger, Honeycomb, or DataDog.
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.
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.
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.
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.
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:
/prisma/migrations folder)SIGINT, exit code (130).prisma format now uses a Wasm moduleInitially, 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.
⚠️ 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:
mode: insensitive alphanumeric comparisons (e.g. “a” > “Z”) didn’t work (GitHub issue)mode: insensitive didn’t exclude undefined (GitHub issue)isEmpty: false on lists types (e.g. String[]) returned true when a list is empty (GitHub issue)hasEvery on list types wasn’t aligned with the SQL implementations (GitHub issue)⚠️ 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:
await prisma.log.findMany({
where: {
NOT: {
meta: {
string_contains: "GET"
}
}
}
})
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_containsstring_starts_withstring_ends_witharray_containsarray_starts_witharray_ends_withgt/gte/lt/lteThe Prisma language server now provides Symbols 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. This makes it easier to navigate to a block in 1 clickA few things to note about the improvement are that:
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.
We've renamed the metrics — counters, gauges, and histograms — returned from prisma.$metrics() to make it a little easier to understand at a glance.
| Previous | Updated |
|---|---|
query_total_operations | prisma_client_queries_total |
query_total_queries | prisma_datasource_queries_total |
query_active_transactions | prisma_client_queries_active |
query_total_elapsed_time_ms | prisma_client_queries_duration_histogram_ms |
pool_wait_duration_ms | prisma_client_queries_wait_histogram_ms |
pool_active_connections | prisma_pool_connections_open |
pool_idle_connections | prisma_pool_connections_idle |
pool_wait_count | prisma_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.
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.
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.
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.
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.
P2034 error code for transaction conflicts or deadlocksWhen 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.
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.
<Meetup title="TypeScript Berlin #10" meetupLink="https://www.meetup.com/typescript-berlin/events/289599295/" youtubeLink="https://youtube.com/playlist?list=PLn2e1F9Rfr6kDEtn-zIyaqPw2qJsbO6VR" talks={[ { title: 'Time for the framework-agnostic app has come?', author: 'Ema Suriano', }, { title: 'Fullstack Type Safety (Remix Edition)', author: 'Alex Ruheni', }, { title: 'Module-Federation: A game-changer in JavaScript architecture', author: 'Vitor Alencar', } ]} imagePath="/blog/posts/meetup-typescript.png" />
<Meetup title="Rust and Tell - EuroRust B-Sides" meetupLink="https://www.meetup.com/rust-berlin/events/288175448/" youtubeLink="https://www.youtube.com/playlist?list=PL85XCvVPmGQhAqjkGfixrAJaiPtStajXt" talks={[ { title: 'Case study: Rust in axle OS', author: 'Philip Tennen', }, { title: 'Let our rusty crab 🦀 explore the depths of the C 🌊', author: 'Yvan Sraka', }, { title: 'Do not break GraphQL, extend it!', author: 'Michal Rosteck', } ]} imagePath="/blog/posts/meetup-rust.png" />
<Meetup title="GraphQL Berlin #26" meetupLink="https://www.meetup.com/graphql-berlin/events/287036184/" youtubeLink="https://www.youtube.com/playlist?list=PLn2e1F9Rfr6ld32vrXcdVS6JGzndBcsqk" talks={[ { title: 'Are you using GraphQL the intended way? ', author: 'Laurin Quast (The Guild)', }, { title: 'The future of GraphQL IDEs', author: 'Rikki Schult (GraphQL Foundation) and Thomas Heyenbrock (Stellate)', }, { title: 'Do not break GraphQL, extend it!', author: 'Paolo Insogna (NearForm)', } ]} imagePath="/blog/posts/meetup-graphql.png" />
<Meetup title="Rust and Tell — BBQ Edition" meetupLink="https://www.meetup.com/rust-berlin/events/287813728/" youtubeLink="https://www.youtube.com/playlist?list=PL85XCvVPmGQhAqjkGfixrAJaiPtStajXt" talks={[ { title: 'Hot code reload in Rust', author: 'Robert K', }, { title: 'Using Rust inside Scala with "robusta_jni"', author: 'Bogdan K', } ]} imagePath="/blog/posts/meetup-rust.png" />
<Meetup title="TypeScript Berlin #9" meetupLink="https://www.meetup.com/typescript-berlin/events/287592005/" youtubeLink="https://youtube.com/playlist?list=PLn2e1F9Rfr6kDEtn-zIyaqPw2qJsbO6VR" talks={[ { title: 'Type Guards and how they can improve your code quality', author: 'Benny Neugebauer (South Pole)', }, { title: 'How to make sure types are not lying to you?', author: 'Fabien Bernard (Xata)', }, { title: 'Introduction to Data Modeling with Algebraic Data Types in TypeScript with Alge', author: 'Jason Kuhrt (Prisma)', } ]} imagePath="/blog/posts/meetup-typescript.png" />
</MeetupList>try-prisma CLItry-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:
npx try-prisma
Read more on Try Prisma: The Fastest Way to Explore Prisma Examples.
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:
Submit an application through our application form.
Every other Thursday, our developer advocates, Nikolas Burk, Alex Ruheni, Tasin Ishmam, Sabin 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:
<Youtube videoId="-0kwU2y0SCA" />We published several videos this quarter on our YouTube channel. Check them out, and subscribe to not miss out on future videos.
@@map and @mapWe published several articles on our blog this quarter:
satisfies Your Prisma WorkflowsWe also published several technical articles on the Data Guide that you might find useful:
Also, we're hiring for various roles! If you're interested in joining us, check out our jobs page.
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.