Query data from MySQL, PostgreSQL & SQL Server databases with Prisma – a type-safe TypeScript ORM for Node.js
Prisma makes working with data easy! It offers a type-safe Node.js & TypeScript ORM, global database caching, connection pooling, and real-time database events.
// 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.
1// Define the `User` table in the database2model User {3 id String @id @default(cuid())4 email String @unique5 password String6 name String?7 posts Post[]8}9
10// Define the `Post` table in the database11model Post {12 id String @id @default(cuid())13 createdAt DateTime @default(now())14 title String15 content String?16 authorId String17 author User @relation(fields: [authorId], references: [id])18}
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.
1type User = {2 id: string3 email: string4 password: string5 name: string | null6}7
8export type Post = {9 id: string10 createdAt: Date11 title: string12 content: string | null13 authorId: string14}
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
We have multiple channels where you can engage with members of our community as well as the Prisma team.