• Stars
    star
    36,195
  • Rank 395 (Top 0.01 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB

Prisma

Prisma

Discord

Quickstart   •   Website   •   Docs   •   Examples   •   Blog   •   Discord   •   Twitter

What is Prisma?

Prisma 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.

The Prisma ORM can also further be extended with these Prisma products:

Getting started

The fastest way to get started with Prisma is by following the Quickstart (5 min).

The Quickstart is based on a preconfigured SQLite database. You can also get started with your own database (PostgreSQL and MySQL) by following one of these guides:

How Prisma works

This section provides a high-level overview of how Prisma 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
// Run inside `async` function
const allUsers = await prisma.user.findMany()
Include the posts relation on each returned User object
// Run inside `async` function
const allUsers = await prisma.user.findMany({
  include: { posts: true },
})
Filter all Post records that contain "prisma"
// Run inside `async` function
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
// Run inside `async` function
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
// Run inside `async` function
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 Slack, Discord, and here on GitHub.

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.

👉 Ask a question

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.

👉 Create bug report

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!

👉 Submit feature request

Contributing

Refer to our contribution guidelines and Code of Conduct for contributors.

Tests Status

  • Prisma Tests Status:
    Prisma Tests Status
  • Ecosystem Tests Status:
    Ecosystem Tests Status

More Repositories

1

prisma1

💾 Database Tools incl. ORM, Migrations and Admin UI (Postgres, MySQL & MongoDB) [deprecated]
Scala
16,608
star
2

prisma-examples

🚀 Ready-to-run Prisma example projects
TypeScript
5,760
star
3

studio

🎙️ The easiest way to explore and manipulate your data in all of your Prisma projects.
1,722
star
4

prisma-client-js

Type-safe database client for TypeScript & Node.js (ORM replacement)
TypeScript
1,466
star
5

prisma-engines

🚂 Engine components of Prisma ORM
Rust
1,095
star
6

docs

📚 Prisma Documentation
MDX
940
star
7

migrate

Issues for Prisma Migrate are now tracked at prisma/prisma. This repo was used to track issues for Prisma Migrate Experimental and is now deprecated.
TypeScript
766
star
8

quaint

SQL Query AST and Visitor for Rust
Rust
583
star
9

tiberius

TDS 7.2+ (Microsoft SQL Server) driver for Rust
Rust
291
star
10

lens

🔬 Prisma design system
TypeScript
287
star
11

language-tools

🌐 Prisma Language Tools = Language Server and Prisma's VS Code extension.
TypeScript
243
star
12

awesome-links

Users browse through a list of curated links and bookmark their favorite ones. Code for prisma.io course.
TypeScript
199
star
13

ecosystem-tests

🥼🧬🧪🔬🧫🦠 - Continuously tests Prisma Client with various operating systems, frameworks, platforms, databases and more.
JavaScript
180
star
14

database-schema-examples

Database Schema Examples we strive to support in Prisma
TSQL
171
star
15

dataguide

🗄️ Prisma's Data Guide - A growing library of articles focused on making databases more approachable.
MDX
142
star
16

prisma-client-extensions

Examples of Prisma Client extensions.
TypeScript
130
star
17

blog-backend-rest-api-nestjs-prisma

A simple backend REST API for a blog built using NestJS, Prisma, PostgreSQL and Swagger.
TypeScript
130
star
18

prisma-test-utils

A collection of data model agnostic test utils.
TypeScript
111
star
19

blogr-nextjs-prisma

TypeScript
107
star
20

specs

⚠ This repository is not actively used any more, please check out the Prisma Documentation for updated information on Prisma. ⚠
Go
87
star
21

fullstack-prisma-nextjs-blog

Fullstack Blog with Next.js and Prisma
TypeScript
85
star
22

extension-read-replicas

Prisma Client Extension to add read replica support to your Prisma Client
TypeScript
84
star
23

deployment-example-vercel

Prisma deployment to Vercel example
JavaScript
74
star
24

text-editors

TypeScript
73
star
25

faunadb-rust

FaundaDB client for Rust
Rust
62
star
26

prisma-templates

Prisma templates for major cloud providers
52
star
27

prisma1-upgrade

Prisma 1 Upgrade is a CLI tool to help Prisma 1 users upgrade to Prisma 2.x or newer.
TypeScript
51
star
28

try-prisma

TypeScript
45
star
29

women-world-wide

JavaScript
41
star
30

codemods

A Collection of Codemods for Prisma 2
JavaScript
34
star
31

vim-prisma

Prisma support for Vim
Vim Script
32
star
32

nestjs-workshop-prisma-day-22

REST API for a rudimentary blog - from Prisma Day 22 NestJS workshop
TypeScript
25
star
33

prisma-nuxt

Prisma example showing how to use Prisma in a Nuxt application.
Vue
25
star
34

engines-wrapper

🌯 @prisma/engines-version npm package
TypeScript
20
star
35

accelerate-speed-test

TypeScript
18
star
36

deployment-example-netlify

Prisma deployment to Netlify example
JavaScript
16
star
37

quickstart

🏁 Starter templates for the 5min Quickstart in the Prisma docs.
JavaScript
16
star
38

prisma-edge-functions

TypeScript
15
star
39

studio-vercel-guide

A guide to deploying Studio alongside your app on Vercel
JavaScript
13
star
40

prisma-fmt-wasm

💾 Build and release automation for @prisma/prisma-fmt-wasm
Shell
12
star
41

ent

An entity layer for Prisma 1 that uses the DataMapper pattern.
TypeScript
12
star
42

connection-string

connection-string + @pimeys/connection-string
Rust
12
star
43

reflector

🪞 Utilities for meta-level interactions with the Prisma toolkit in Node.js.
TypeScript
12
star
44

engine-images

🖼️ Build & test images for Prisma engines.
Shell
11
star
45

prisma-client-extension-starter

Starter template repository for building publishable Prisma Client extensions
TypeScript
10
star
46

prisma1-json-schema

JSON schema of prisma.yml files
TypeScript
10
star
47

templates

Prisma templates packaged up for programatic consumption.
TypeScript
10
star
48

eslint-config-prisma

🧹 Prisma's .eslintrc as an extensible shared config.
JavaScript
10
star
49

styles

Shared style resources between Graphcool projects
CSS
9
star
50

demo-sveltekit

Demo app for Sveltekit article
Svelte
8
star
51

pris.ly

Prisma shortlink service (hosted on Vercel)
7
star
52

prisma1-examples

TypeScript
7
star
53

prisma2-development-environment

This project combines prisma2, lift and photonjs into one workspace, builds and installs all dependencies for you.
TypeScript
7
star
54

sublimeText3

Sublime Text 3 package supporting syntax highlighting.
6
star
55

migrate-from-sequelize-to-prisma

A migration guide from Sequelize to Prisma example
JavaScript
6
star
56

pulse-starter

A Pulse starter project. To be used inside of a railway.app template, locally, or with another Pulse-ready database.
TypeScript
6
star
57

opentls

TLS connections for Rust using OpenSSL
Rust
6
star
58

prisma-admin-custom-components

Examples of custom components for Prisma Admin
JavaScript
6
star
59

prisma-content-feedback

Feedback for documentation, articles, tutorials, examples, ...
6
star
60

prisma-admin-feedback

Feedback for Prisma Admin (currently in invite-only preview)
6
star
61

prisma-1-cloud-feedback

Feedback for Prisma Cloud
5
star
62

migrate-from-typeorm-to-prisma

TypeScript
5
star
63

binding-argument-transform

A library to make Prisma 1 arguments compatible with Prisma 2.
TypeScript
5
star
64

pulse-starter-old

A starter project to get you up and running with pulse.
TypeScript
4
star
65

nextjs-edge-functions

Demo of using Next.js with Prisma ORM deployed to Vercel Edge Functions
TypeScript
4
star
66

prisma-day

Prisma Day Code of Conduct
4
star
67

db-testing-pool

🏖️ Utility to create a pool of ephemeral databases for parallel testing (e.g. with Jest, AVA, ...)
4
star
68

prisma-read-replica-middleware

TypeScript
4
star
69

prisma-platformatic

Prisma 💚 Platformatic exploration
JavaScript
4
star
70

p1-to-p2-upgrade-path-feedback

4
star
71

presskit

Presskit for Prisma
3
star
72

deployment-example-cloudflare-workers

Cloudflare workers deployment example
TypeScript
3
star
73

prisma-example-starter-template

3
star
74

metrics-tutorial-prisma

Database Metrics with Prisma, Prometheus & Grafana
TypeScript
3
star
75

tech-writer-task-template

This repository is a template for Technical Writer candidates to use.
JavaScript
3
star
76

read-replicas-demo

TypeScript
2
star
77

pulse-railway-pg-config

A railway.app project template. Contains a Pulse ready postgres database and set up service. Read more about pulse
TypeScript
2
star
78

db-push-non-idempotent-schemas

Collection of schemas that don't roundtrip if you db pull, then db push
Nix
2
star
79

prisma-indexes

TypeScript
2
star
80

prisma-fundamentals

An Instruqt lab to introduce students to the Prisma Schema
Shell
2
star
81

.github

Org level configuration for installed GitHub apps
2
star
82

benching_setup

TypeScript
2
star
83

migrate-from-mongoose-to-prisma

JavaScript
1
star
84

prisma-client-lib-go

Runtime of Prisma (v1) Go Client.
Go
1
star
85

fivetran-npm-downloads

Python
1
star
86

fullstack-prisma-turso

TypeScript
1
star
87

accelerate-nextjs-starter

TypeScript
1
star
88

fullstack-prisma-turso-embedded-db

TypeScript
1
star
89

ci-reports

Repository for various reports from pull requests
HTML
1
star
90

pulse-resend-demo

TypeScript
1
star
91

deployment-example-lambda-serverless-framework

TypeScript
1
star
92

language-tools-gitpod

Shell
1
star
93

test-vercel-access

HTML
1
star
94

client-planning

Placeholder repository for client planning tickets
1
star
95

action-node-cache-dependencies

Install and cache node modules.
1
star
96

docs-tools

Python
1
star
97

orm-cloudflare-worker-list-binaries

A cloudflare worker to list the contents of the `prisma-builds` bucket
TypeScript
1
star
98

tracing-tutorial-prisma

Reference code for "Get Started With Tracing Using OpenTelemetry and Prisma Tracing".
TypeScript
1
star
99

react-native-prisma

TypeScript
1
star
100

pdp-spike-nextjs-opentelemetry

TypeScript
1
star