Query data from MySQL, PostgreSQL & SQL Server databases with Prisma – a type-safe TypeScript ORM for Node.js
Prisma is an open-source ORM that drastically simplifies data modeling, migrations, and data access for SQL databases in Node.js and TypeScript.
// Creating a new recordawait prisma.user.create({ firstName: “Alice”, email: “alice@prisma.io”})
id firstName email 1 Bobby bobby@tables.io2 Nilufar nilu@email.com3 Jürgen jums@dums.edu4 Alice alice@prisma.io
TypeScript is a statically typed language which builds on JavaScript. It provides you with all the functionality of JavaScript with the additional ability to type and verify your code which saves you time by catching errors and providing fixes before you run your code. All valid JavaScript code is also TypeScript code which makes TypeScript easy for you to adopt.
Prisma is an ORM for Node.js and TypeScript that gives you the benefits of type-safety at zero cost by auto-generating types from your database schema. It's ideal for building reliable data intensive application. Prisma makes you more confident and productive when storing data in a relational database. You can use it with any Node.js server framework to interact with your database.
The Prisma schema uses Prisma's modeling language to define your database schema and to generate the corresponding TypeScript types. It makes data modeling easy and intuitive, especially when it comes to modeling relations.
The types generated from the Prisma schema ensure that all your database queries are type safe. Prisma Client gives you a fantastic autocomplete experience so you can move quickly and be sure you don't write an invalid query.
// Define the `User` table in the databasemodel User { id String @id @default(cuid()) email String @unique password String name String? posts Post[]}
// Define the `Post` table in the databasemodel Post { id String @id @default(cuid()) createdAt DateTime @default(now()) title String content String? authorId String author User @relation(fields: [authorId], references: [id])}
type User = { id: string email: string password: string name: string | null}
export type Post = { id: string createdAt: Date title: string content: string | null authorId: string}
Define your schema once and Prisma will generate the TypeScript types for you. No need for manual syncing between the types in your database schema and application code.
The code below demonstrates how database queries with Prisma are fully type safe – for all queries, including partial queries, and relations.
Queries with Prisma Client always have their return type inferred making it easy to reason about the returned data – even when you fetch relations.
1// Inferred type:2// User & {3// posts: Post[];4// }5const user = await prisma.user.create({6 data: {7 email: 'alice@prisma.io',8 password: '0ee4808f893b8e05bdd251048d5c4c8af8bb89403676dda95619841a481f8e87',9 name: 'Alice',10 posts: {11 create: {12 title: 'Learn how to use Prisma with TypeScript',13 content: 'https://www.prisma.io/docs/',14 },15 },16 },17 include: {18 posts: true,19 },20})
Queries with Prisma Client always have their return type inferred making it easy to reason about the returned data – even when you fetch relations.
1// Inferred type:2// User & {3// posts: Post[];4// }5const user = await prisma.user.create({6 data: {7 email: 'alice@prisma.io',8 password: '0ee4808f893b8e05bdd251048d5c4c8af8bb89403676dda95619841a481f8e87',9 name: 'Alice',10 posts: {11 create: {12 title: 'Learn how to use Prisma with TypeScript',13 content: 'https://www.prisma.io/docs/',14 },15 },16 },17 include: {18 posts: true,19 },20})
Prisma Client ensures fully type-safe database queries so that you never write an invalid query
Prisma's built-in dataloader ensures optimized and performant database queries, even for N+1 queries.
Prisma helps you write your queries with rich autocompletion as you write queries
Queries with Prisma Client always have their return type inferred making it easy to reason about your data.
Map your Prisma schema to the database so you don't need to write SQL to manage your database schema.
Prisma Client reduces boilerplates by providing convenient APIs for common database features.
1const users = await prisma.user.findMany({2 where: {3 email: {4 endsWith: '@prisma.io',5 }6 },7 include: {8 p9 }10})
At Prisma, we love TypeScript and believe in its bright future. Since the inception of Prisma, we've pushed the TypeScript compiler to its limits in order to provide unprecedented type-safe database access, and rich autocompletion for a delightful developer experience.
Prisma is built with type-safety at its heart so that you make less mistakes. By tapping into TypeScript's structural type system Prisma maps database queries into structural types so you can know the precise shape of the data returned for every Prisma Client query you write.
The TypeScript Berlin Meetup started in 2019 and is one of the most popular TypeScript Meetups in the world
Ready-to-run example projects using Prisma, TypeScript and a variety of different frameworks and API technologies
A tutorial series for building a modern backend with hapi and Prisma
Get Involved
Get help and engage with thousands of TypeScript and Prisma developers on Slack
We'd love to see what you're building with TypeScript and Prisma
Show your TypeScript + Prisma love with free custom stickers