Website • Docs • Blog • Forum • Slack • Twitter • OSS • Learn
Prisma the data layer for modern applications. It replaces traditional ORMs and data access layers with a universal database abstraction used via the Prisma client. Prisma is to build GraphQL servers, REST APIs & more.
- Prisma client for various languages such as JavaScript, TypeScript,Flow, Go.
- Supports multiple databases such as MySQL, PostgreSQL, MongoDB (see all supported databases).
- Type-safe database access including filters, aggregations, pagination and transactions.
- Realtime event systems for your database to get notified about database events.
- Declarative data modeling & migrations (optional) with simple SDL syntax.
- Quickstart
- Examples
- Architecture
- Is Prisma an ORM?
- Database Connectors
- GraphQL API
- Community
- Contributing
brew install prisma
brew tap prisma/prisma
Alternative: Install with NPM or Yarn
npm install -g prisma
# or
yarn global add prisma
To setup Prisma, you need to have Docker installed. Run the following command to get started with Prisma:
prisma init hello-world
The interactice CLI wizard now helps you with the required setup:
- Select Create new database (you can also use an existing database or a hosted demo database)
- Select the database type: MySQL or PostgreSQL
- Select the language for the generated Prisma client: TypeScript, Flow, JavaScript or Go
Once the wizard has terminated, run the following commands to setup Prisma:
cd hello-world
docker-compose up -d
Edit datamodel.prisma
to define your data model using SDL syntax:
type User {
id: ID! @unique
email: String @unique
name: String!
posts: [Post!]!
}
type Post {
id: ID! @unique
title: String!
published: Boolean! @default(value: "false")
author: User
}
Each model is mapped to a table in your database schema.
To deploy your Prisma API, run the following command:
prisma deploy
The Prisma API is deployed based on the datamodel and exposes CRUD & realtime operations for each model in that file.
The Prisma client connects to the Prisma API and lets you perform read and write operations in your database. This section explains how to use the Prisma client from JavaScript.
Create a new Node script inside the hello-world
directory:
touch index.js
Now add the following code to it:
const { prisma } = require('./generated/prisma')
// A `main` function so that we can use async/await
async function main() {
// Create a new user with a new post
const newUser = await prisma
.createUser({
name: "Alice"
posts: {
create: {
title: "The data layer for modern apps",
}
},
})
console.log(`Created new user: ${newUser.name} (ID: ${newUser.id})`)
// Read all users from the database and print them to the console
const allUsers = await prisma.users()
console.log(allUsers)
// Read all posts from the database and print them to the console
const allPosts = await prisma.posts()
console.log(allPosts)
}
main().catch(e => console.error(e))
Finally, run the code using the following command:
node index.js
See more API operations
const usersCalledAlice = await prisma
.users({
where: {
name: "Alice"
}
})
const updatedUser = await prisma
.updateUser({
where: { id: "__USER_ID__" },
data: { email: "alice@prisma.io" }
})
const deletedUser = await prisma
.deleteUser({ id: "__USER_ID__" })
const postsByAuthor = await prisma
.user({ email: "alice@prisma.io" })
.posts()
Learn how to build an app using your Prisma client or read more about how Prisma works.
Collection of Prisma example projects 💡
- application-server
- authentication
- cli-tool
- data-modelling
- hooks
- permissions-with-shield
- postgres
- resolver-forwarding
- server-side-subscriptions
- subscriptions
- travis
- yml-structure
You can also check the AirBnB clone example we built as a fully-featured demo app for Prisma.
Prisma takes the role of a data access layer in your backend architecture by connecting your API server to your databases. It enables a layered architecture which leads to better separation of concerns and improves maintainability of the entire backend.
Acting as a GraphQL database proxy, Prisma provides a GraphQL-based abstraction for your databases enabling you to read and write data with GraphQL queries and mutations. Using Prisma bindings, you can access Prisma's GraphQL API from your programming language.
Prisma servers run as standalone processes which allows for them to be scaled independently from your API server.
Prisma provides a mapping from your API to your database. In that sense, it solves similar problems as conventional ORMs. The big difference between Prisma and other ORMs is how the mapping is implemented.
Prisma takes a radically different approach which avoids the shortcomings and limitations commonly experienced with ORMs. The core idea is that Prisma turns your database into a GraphQL API which is then consumed by your API server (via GraphQL binding). While this makes Prisma particularly well-suited for building GraphQL servers, it can definitely be used in other contexts as well.
Here is how Prisma compares to conventional ORMs:
- Expressiveness: Full flexibility thanks to Prisma's GraphQL API, including relational filters and nested mutations.
- Performance: Prisma uses various optimization techniques to ensure top performance in complex scenarios.
- Architecture: Using Prisma enables a layered and clean architecture, allowing you to focus on your API layer.
- Type safety: Thanks to GraphQL's strong type system you're getting a strongly typed API layer for free.
- Realtime: Out-of-the-box support for realtime updates for all events happening in the database.
Database connectors provide the link between Prisma and the underlying database.
You can connect the following databases to Prisma already:
- MySQL
- Postgres
More database connectors will follow.
If you are interested to participate in the preview for one of the following connectors, please reach out in our Slack.
We are still collecting use cases and feedback for the API design and feature set of the following connectors:
- MS SQL Connector
- Oracle Connector
- ArangoDB Connector
- Neo4j Connector
- Druid Connector
- Dgraph Connector
- DynamoDB Connector
- Cloud Firestore Connector
- CockroachDB Connector
- Cassandra Connector
- Redis Connector
- AWS Neptune Connector
- CosmosDB Connector
- Influx Connector
Join the discussion or contribute to influence which we'll work on next!
The most important component in Prisma is the GraphQL API:
- Query, mutate & stream data via a auto-generated GraphQL CRUD API
- Define your data model and perform migrations using GraphQL SDL
Prisma's auto-generated GraphQL APIs are fully compatible with the OpenCRUD standard.
Prisma has a community of thousands of amazing developers and contributors. Welcome, please join us! 👋
- Forum
- Slack
- Meetup
- GraphQL Europe (June 15, Berlin)
- GraphQL Day
Contributions are welcome and extremely helpful 🙌 Please refer to the contribution guide for more information.
Releases are separated into three channels: alpha, beta and stable. You can learn more about these three channels and Prisma's release process here.