Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
What is prisma prisma
What is Prisma?
Prisma ORM is a next-generation ORM that consists of these tools:
- Prisma Client: Auto-generated and type-safe query builder for Node.js & TypeScript
- Prisma Migrate: Declarative data modeling & migration system
- Prisma Studio: GUI to view and edit data in your database
Prisma Client can be used in any Node.js or TypeScript backend application (including serverless applications and microservices). This can be a REST API, a GraphQL API, a gRPC API, or anything else that needs a database.
If you need a database to use with Prisma ORM, check out Prisma Postgres.
Getting started
Quickstart (5min)
The fastest way to get started with Prisma is by following the quickstart guides. You can choose either of two databases:
Bring your own database
If you already have your own database, you can follows these guides:
How Prisma ORM works
This section provides a high-level overview of how Prisma ORM works and its most important technical components. For a more thorough introduction, visit the Prisma documentation.
The Prisma schema
Every project that uses a tool from the Prisma toolkit starts with a Prisma schema file. The Prisma schema allows developers to define their application models in an intuitive data modeling language. It also contains the connection to a database and defines a generator:
// Data source
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// Generator
generator client {
provider = "prisma-client-js"
}
// Data model
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author User? @relation(fields: [authorId], references: [id])
authorId Int?
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
In this schema, you configure three things:
- Data source: Specifies your database connection (via an environment variable)
- Generator: Indicates that you want to generate Prisma Client
- Data model: Defines your application models
The Prisma data model
On this page, the focus is on the data model. You can learn more about Data sources and Generators on the respective docs pages.
Functions of Prisma models
The data model is a collection of models. A model has two major functions:
- Represent a table in the underlying database
- Provide the foundation for the queries in the Prisma Client API
Getting a data model
There are two major workflows for "getting" a data model into your Prisma schema:
- Generate the data model from introspecting a database
- Manually writing the data model and mapping it to the database with Prisma Migrate
Once the data model is defined, you can generate Prisma Client which will expose CRUD and more queries for the defined models. If you're using TypeScript, you'll get full type-safety for all queries (even when only retrieving the subsets of a model's fields).
Accessing your database with Prisma Client
Generating Prisma Client
The first step when using Prisma Client is installing its npm package:
npm install @prisma/client
Note that the installation of this package invokes the prisma generate
command which reads your Prisma schema and generates the Prisma Client code. The code will be located in node_modules/.prisma/client
, which is exported by node_modules/@prisma/client/index.d.ts
.
After you change your data model, you'll need to manually re-generate Prisma Client to ensure the code inside node_modules/.prisma/client
gets updated:
npx prisma generate
Refer to the documentation for more information about "generating the Prisma client".
Using Prisma Client to send queries to your database
Once the Prisma Client is generated, you can import it in your code and send queries to your database. This is what the setup code looks like.
Import and instantiate Prisma Client
You can import and instantiate Prisma Client as follows:
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
or
const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
Now you can start sending queries via the generated Prisma Client API, here are a few sample queries. Note that all Prisma Client queries return plain old JavaScript objects.
Learn more about the available operations in the Prisma Client docs or watch this demo video (2 min).
Retrieve all User
records from the database
const allUsers = await prisma.user.findMany()
Include the posts
relation on each returned User
object
const allUsers = await prisma.user.findMany({
include: { posts: true },
})
Filter all Post
records that contain "prisma"
const filteredPosts = await prisma.post.findMany({
where: {
OR: [{ title: { contains: 'prisma' } }, { content: { contains: 'prisma' } }],
},
})
Create a new User
and a new Post
record in the same query
const user = await prisma.user.create({
data: {
name: 'Alice',
email: '[email protected]',
posts: {
create: { title: 'Join us for Prisma Day 2021' },
},
},
})
Update an existing Post
record
const post = await prisma.post.update({
where: { id: 42 },
data: { published: true },
})
Usage with TypeScript
Note that when using TypeScript, the result of this query will be statically typed so that you can't accidentally access a property that doesn't exist (and any typos are caught at compile-time). Learn more about leveraging Prisma Client's generated types on the Advanced usage of generated types page in the docs.
Community
Prisma has a large and supportive community of enthusiastic application developers. You can join us on Discord and here on GitHub.
Badges
Built something awesome with Prisma? 🌟 Show it off with these badges, perfect for your readme or website.
[](https://prisma.io)
[](https://prisma.io)
MCP server
The Prisma CLI includes a Prisma MCP server. It's started via this CLI command:
npx prisma mcp
Most AI tools support a JSON-based configuration for MCP servers looking like this:
{
"mcpServers": {
"Prisma": {
"command": "npx",
"args": ["-y", "prisma", "mcp"]
}
}
}
Prisma's MCP server gives AI agents the ability to manage Prisma Postgres databases (e.g. spin up new database instances or run schema migrations).
Security
If you have a security issue to report, please contact us at [email protected].
Support
Ask a question about Prisma
You can ask questions and initiate discussions about Prisma-related topics in the prisma
repository on GitHub.
Create a bug report for Prisma
If you see an error message or run into an issue, please make sure to create a bug report! You can find best practices for creating bug reports (like including additional debugging output) in the docs.
Submit a feature request
If Prisma currently doesn't have a certain feature, be sure to check out the roadmap to see if this is already planned for the future.
If the feature on the roadmap is linked to a GitHub issue, please make sure to leave a 👍 reaction on the issue and ideally a comment with your thoughts about the feature!
Contributing
Refer to our contribution guidelines and Code of Conduct for contributors.
Tests Status
Leave a Comment
Frequently Asked Questions
What is MCP?
MCP (Model Context Protocol) is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications, providing a standardized way to connect AI models to different data sources and tools.
What are MCP Servers?
MCP Servers are lightweight programs that expose specific capabilities through the standardized Model Context Protocol. They act as bridges between LLMs like Claude and various data sources or services, allowing secure access to files, databases, APIs, and other resources.
How do MCP Servers work?
MCP Servers follow a client-server architecture where a host application (like Claude Desktop) connects to multiple servers. Each server provides specific functionality through standardized endpoints and protocols, enabling Claude to access data and perform actions through the standardized protocol.
Are MCP Servers secure?
Yes, MCP Servers are designed with security in mind. They run locally with explicit configuration and permissions, require user approval for actions, and include built-in security features to prevent unauthorized access and ensure data privacy.
Related MCP Servers
PostgreSQL MCP Server
A Model Context Protocol server that provides read-only access to PostgreSQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.
chrisdoc hevy mcp
sylphlab pdf reader mcp
An MCP server built with Node.js/TypeScript that allows AI agents to securely read PDF files (local or URL) and extract text, metadata, or page counts. Uses pdf-parse.
aashari mcp server atlassian bitbucket
Node.js/TypeScript MCP server for Atlassian Bitbucket. Enables AI systems (LLMs) to interact with workspaces, repositories, and pull requests via tools (list, get, comment, search). Connects AI directly to version control workflows through the standard MCP interface.
aashari mcp server atlassian confluence
Node.js/TypeScript MCP server for Atlassian Confluence. Provides tools enabling AI systems (LLMs) to list/get spaces & pages (content formatted as Markdown) and search via CQL. Connects AI seamlessly to Confluence knowledge bases using the standard MCP interface.
Zzzccs123 mcp sentry
mcp sentry for typescript sdk
zhuzhoulin dify mcp server
zhongmingyuan mcp my mac
zhixiaoqiang desktop image manager mcp
MCP 服务器,用于管理桌面图片、查看详情、压缩、移动等(完全让Trae实现)
zhixiaoqiang antd components mcp
An MCP service for Ant Design components query | 一个减少 Ant Design 组件代码生成幻觉的 MCP 服务,包含系统提示词、组件文档、API 文档、代码示例和更新日志查询
Submit Your MCP Server
Share your MCP server with the community
Submit Now