Prisma – Database tools for modern application development
prisma.io
prisma.io
Does their documentation today feel like the doc team and technical writing team have an actual seat at the table or does it still feel like the place is run by a bunch of architecture astronauts who think docs just happen after the fact?
Would be great if you can give it another try, as I'm convinced that the docs improved significantly over the last year. Disclaimer: I work at Prisma.
It's true that we haven't focussed on a mobile experience for the docs so far (assuming a primary use case for the docs is when being used on your computer as you're using Prisma). However, we see that many people like to browse docs on their phones to learn about the tool, so we are now making it a priority to make our docs responsive! Thanks for the feedback.
Question specific to this autogenerated client: does that mean I have to bump client version numbers every time my backend schema changes? Does this help if I'm building a backwards-compatible api, like Stripe's API [1]? Apologies if this is already answered in your docs.
Do you have specific examples of cutting edge patterns they use that you can share? I'm always interested in seeing concrete examples of (often) abstract patterns/concepts.
Thanks a lot for the positive feedback, we appreciate it a lot! As to your question, I assume with "backend schema" you're talking about the Prisma datamodel? Whenever you change the datamodel, you're also re-generating your Prisma client. So, it can definitely make sense to version your Prisma client as your datamodel changes. Does this clear it up?
The main purpose of the code generation really is to have proper typings for all database operations based on the datamodel. For example, if you're adding a new model type to the datamodel, Prisma doesn't only generate according models in your programming language, it also generates types that facilitate filtering, pagination, ordering and any other operations of your database.
The only issue that we did encounter so far is that it doesn't know play well easily when you have more than one instance of a Prisma server behind a load balancer that your backend connect to.
Another interesting and unique approach I'd love to see get more attention is Mammoth[0]. Instead of abstracting the database away, you define columns using its raw primitives (in this case, Postgres) and in return get a type-safe client, along with auto-generated migrations.
I imagine this approach allows you to leverage the features of the database much more easily. And Postgres has quite a lot of rich features to take advantage of! :)
PS. maintainer of mammoth here. Thanks for the mention.
PS. We've looked into mammoth a lot for inspiration and really liked it, great work!
Prisma uses introspection to generate a feature-rich, type-safe library around your database's schema to reduce or eliminate most of the downsides you traditionally associate with ORMs.
Type safety
Today's ORMs rely on query builders (e.g. await select('users').where('id', 10)) or hand-written classes (e.g. class Product < ApplicationRecord) to map an object to a row. Prisma looks to the database for the information about types and relationships to generate type-safe code specific to your database in every language (e.g. prisma.Products.FindByName("Sponge")).
Bugs caught at compile-time
Another downside of today's ORMs most of them break at runtime, rather than compile time. By generating type-safe database clients, Prisma eliminates any opportunity for breaking database changes to go unnoticed and end up in production.
Better performance
There are a couple advantages of Prisma has over traditional ORMs and raw SQL queries:
• The core of Prisma is written in Rust to have predictably high-performance and flexible caching.
• Prisma is written by database experts and administrators who have seen every database schema under the sun.
Fewer Leaks
Because Prisma has a holistic view of your database's structure, Prisma can generate an API that is better tailored to your application than a traditional ORM. There may be times when you still need to write raw database queries and Prisma will support these escape hatches, but those times are rare and are becoming less common every day.
Generally, think of Prisma as a suite of database tools that simplify workflows in three different areas:
● Database access / ORM (lightweight, auto-generated and type-safe database client for various languages)
● Declarative data modelling and migrations
● Data management with modern admin UI
I think it also differs from traditional ORMs in that it supports multiple databases. We see a trend that many modern apps are built on top of a variety of databases, it might use Posgtres, Elastic, Mongo and Neo4j all at the same time for different purposes. We are embracing this and with the Prisma client it will be possible in the future to access all these data sources in a single, coherent and type-safe API.
Feel free to check out our roadmap to get an idea of what we're working on: https://github.com/prisma/prisma/blob/master/ROADMAP.md
SQL isn’t typed. And writing migrations and client libraries is otherwise painful. That’s basically the value add.
SQL results, coming without any translation layer, are untyped. Your result could be anything from a string to an array with an infinite number of fields.
It doesn’t really get more structure than this big array either, regardless of table representation.
Prisma helps with that.
That would depend on the database's wire protocol, wouldn't it?
It supports various strategies for loading associations, including joins and bulk sideloading (pre-edge when you know what to fetch before parent entities have been loaded, and post-edge when you need parent entities before).
It is still somewhat early stage and the scope is much narrower but it provides a great deal of control to the host application on how the operations are mapped from the graphql layer to the persistence layer.
Is this not what you were talking about?
Hasura I think is good for preexisting db, no migrations? I haven't evaluated it fully.
Yep! We’ve put in a lot of effort to ensure hasura Just Works on an existing db.
Incidentally, to address your last point, Hasura has its own rails like migrations system and an admin UI (that allows DDL and DML) and works well with your existing migrations tooling too if you have it already. The hasura admin UI can create the rails style migration files automatically on your disk as you work on the UI.
EDIT: Never mind, looking at the docs, it looks like they also only support subscriptions... It's understandable to not have support for live queries yet, as it's still a very under-explored territory, but it's still misleading marketing on their part because they explicitly call out support for subscripts _and_ live queries on their website.
Curious how Hasura tackles the N+1 problem for efficient querying in GraphQL? Prisma uses a built-in dataloader implementation for this but I couldn't find anything about query optimization in the Hasura docs.
Also, in the docs on pagination: https://docs.hasura.io/1.0/graphql/manual/queries/pagination...
I'm only seeing examples of offset-based pagination. Is cursor-based pagination on the roadmap as well?
Hasura allows you to turn any "query" to a subscription, essentially live queries.
Hasura's query optimization is actually one of the core features. Hasura is structured as a transpiler that converts GraphQL, adds access control clauses and then renders a single SQL for the database. Very different from a typical ORM approach or the dataloader approach.
More details: https://blog.hasura.io/architecture-of-a-high-performance-gr...
There are some rough edges, but the team is very responsive and they have fixed most of my minor gripes over the past months.
Overall I am happy we chose it and I would choose it again.
it however requires you do this at compile time, not runtime. does prisma do the introspection at runtime?
The downside is (because there is always some), as it's a new tech, problems can pop up and more research have to be made compared to a more old and popular framework.
In any case, I highly recommend you to try it on your own, I'm looking foward to its futur improvements.
> Comparing Prisma to AWS AppSync & Hasura
> With the new understanding of the role of Prisma's CRUD GraphQL API, it becomes clear that Prisma is not in the category of "GraphQL-as-a-Service" anymore.
> Tools like AWS AppSync and Hasura provision a generated GraphQL API for your database (or in the case of AppSync also other data sources). In contrast, Prisma enables simplified and type-safe database access in various languages.
What would be interesting to see is the cost of change i.e. how de-coupled things are to make changes simple.
Changes like: Adding a field To changing a relationship between entities and such.
For anyone who is curious about Nexus, I recommend our blog article series about code-first vs SDL/schema-first GraphQL server development: https://www.prisma.io/blog/the-problems-of-schema-first-grap...
Also, for a quick and ready-to-run example, you can check out this: https://github.com/prisma/prisma-examples/tree/master/node/g...
The main focus of Prisma is the ORM part and not the GraphQL API anymore. We're still using GraphQL to communicate between Query Engine and the backend client in the languages we support like TypeScript or Go, but when communicating with backend to database, GraphQL is not that relevant anymore and rather a separate concern how you want to expose your API later.
When accessing the database from your backend, type-safety is becoming more and more important. Instead of writing a GraphQL string in your code, with the Prisma Client you get a type-safe programmatic API to access your data. You can imagine it as your own SDK. The difference to many ORMs is, that we generate a custom Client for you, which is way more powerful.
Disclaimer: I work at Prisma.
Hopefully that clears it up!
It is very important to understand that Prisma is NOT a GraphQL-as-a-Service like Hasura or Postgraphile. It's really a suite of database tools that you can use for any use case (building GraphQL, REST or gRPC APIs, or use it in any other app where you need a database). We recently wrote a blog post about this topic: https://www.prisma.io/blog/prisma-and-graphql-mfl5y2r7t49c/
Also, the Prisma server (that proxies the database) is indeed currently a mandatory component in the Prisma architecture. However, this requirement will be lifted very soon (as we're currently rewriting the Prisma core in Rust) and it will be possible to run Prisma as a library, just like any other ORM.
Prisma is open-source and you are typically running it in production by running it on your own cloud infrastructure.
The commercial parts of Prisma are called Prisma Cloud and Prisma Enterprise. Prisma Cloud aims to simplify various Prisma workflows such as server and data management, monitoring, backups, migrations/rollbacks, ... We're also planning a "Prisma Serverless" offering so you don't need to host the Prisma server yourself.
That's a great question! We started with a major focus on GraphQL which has now become more generic as Prisma can really be used for any app that uses a DB (REST, gRPC, ...). With that GraphQL history, we've put a lot of focus on the Node/TypeScript ecosystem because that's where GraphQL tooling is most mature. However, we're definitely planning to support more languages in the future. In particular, we are opening the generator API for the Prisma client which means it will be possible for anyone to implement the Prisma client in their own preferred language: https://github.com/prisma/rfcs/blob/client-generators/text/0...
That's slightly weird, bit of a mixed messages situation!
Epilogue: Caveat emptor, rambling ahead. I probably shouldn't write comments when I'm tired.
Hasn't type safe ORM mappings and/or middleware, code generation, been done to death, at least for the JVM languages?
However, as I've been out of the Java loop for a bit, I'm not 100% sure of the stage of ORM like tools/libs today, I might be wrong.
If the admin UI is spectacular, and the migration flawless even with a fair bit of data, those could be useful tools. Neither are easy tasks though.
But still, I have to wonder, is there actually more ways to try to do it, to connect code and relational/graph data?
Feels like there has been so many attempts and that all of them has shown to have their various, by now, surely rather well known limitations?
Better is always possible, though.
However, except for mixing in a bit of graphql and having an additional server, I can't really see what it is they claim is so different?
Though I've been out of the loop for some year I can't have been the only one that have implemented/integrated a graph querying language on top of a ORM(-like) mapping with code generation, similar to Prisma? Or are there really no decent tooling of that kind, still?
Except for admin UI and real-time, I wrote something very similar back in 2007, or something like that. Unfortunately my client weren't interested in open sourcing it, back then it could have been somewhat original.
If I recall correctly, it was a customized Hibernate in the bottom, some code generation for Java - ASP - php - and maybe perl - clients, some fancy dependency injection.
Connect to the database and you got generated all code that was needed for a service you could query for tree fragments of almost arbitrary shape.
Essentially a GraphQL light I quess, as GraphQL wasn't available at the time, if it existed at all.
The http API used JAXWS I believe and it exposed few endpoints for some REST-ish+JSON and SOAP
You could do transactions over multiple requests if you wanted to, and weren't easily scared.
It could obviously prune circular graphs into trees, although that code had a few fun bugs initially.
No streaming though, as the client didn't need it.