Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prisma/prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
https://github.com/prisma/prisma
cockroachdb database javascript mariadb mongo mongodb mongodb-orm mssql mysql nodejs orm postgres postgresql prisma prisma-client query-builder sql-server sqlite sqlserver typescript
Last synced: 3 days ago
JSON representation
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
- Host: GitHub
- URL: https://github.com/prisma/prisma
- Owner: prisma
- License: apache-2.0
- Created: 2019-06-20T13:33:47.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-11-30T13:41:47.000Z (12 days ago)
- Last Synced: 2024-11-30T13:46:11.299Z (12 days ago)
- Topics: cockroachdb, database, javascript, mariadb, mongo, mongodb, mongodb-orm, mssql, mysql, nodejs, orm, postgres, postgresql, prisma, prisma-client, query-builder, sql-server, sqlite, sqlserver, typescript
- Language: TypeScript
- Homepage: https://www.prisma.io
- Size: 120 MB
- Stars: 39,882
- Watchers: 239
- Forks: 1,560
- Open Issues: 3,213
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
- awesome - prisma - 💾 Database Tools incl. ORM, Migrations and Admin UI (Postgres, MySQL & MongoDB) (Scala)
- awesome - prisma/prisma - Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB (TypeScript)
- awesome - prisma/prisma - Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB (TypeScript)
- awesome-nodejs-cn - Prisma - TypeScript 的自动生成类型并且类型安全的查询构建器,可用于替代 ORM 的现代数据库接入方式,支持 PostgreSQL, MySQL 和 SQLite (包 / 数据库)
- awesome-graphql - Prisma - Turn your database into a GraphQL API. Prisma lets you design your data model and have a production ready GraphQL API online in minutes. (Tools / Julia Libraries)
- pure-awesomeness - Prisma
- awesome-faker - prisma - Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB. (Projects using `@faker-js/faker`)
- awesome-nodejs - Prisma - Modern database access (ORM alternative). Auto-generated and type-safe query builder in TypeScript. Supports PostgreSQL, MySQL & SQLite. ![](https://img.shields.io/github/stars/prisma/prisma.svg?style=social&label=Star) (Repository / Database)
- awesome-nodejs-cn - Prisma - **star:39664** 现代数据库访问(ORM替代)。在TypeScript中自动生成和类型安全的查询生成器。支持PostgreSQL, MySQL和SQLite。 ![star > 2000][Awesome] (包 / 数据库)
- awesome-ccamel - prisma/prisma - Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB (TypeScript)
- awesome-libraries - prisma - like schema definiton. (Node.js / Node.js)
- awesome-github-star - prisma - generation ORM for Node.js & TypeScript \| PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB | prisma | 34009 | (TypeScript)
- awesome-list - prisma
- react-cheatsheet - Prisma
- awesome-repos - prisma
- awesome-list - prisma - generation ORM for Node.js & TypeScript \| PostgreSQL, MySQL, MariaDB, SQL Server, SQLite & MongoDB (Preview) | prisma | 15564 | (TypeScript)
- awesome-nodejs - Prisma - Modern database access (ORM alternative). Auto-generated and type-safe query builder in TypeScript. Supports PostgreSQL, MySQL & SQLite. (Packages / Database)
- awesome-nodejs - prisma - Next-generation Node.js and TypeScript ORM (Uncategorized / Uncategorized)
- awesome-fe-resources - prisma
- StarryDivineSky - prisma/prisma
- jimsghstars - prisma/prisma - Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB (TypeScript)
- awesome-star-libs - prisma / prisma
- awesome-starred - prisma/prisma - Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB (typescript)
README
![Prisma](https://i.imgur.com/h6UIYTu.png)
## What is Prisma?
Prisma ORM is a **next-generation ORM** that consists of these tools:
- [**Prisma Client**](https://www.prisma.io/docs/concepts/components/prisma-client): Auto-generated and type-safe query builder for Node.js & TypeScript
- [**Prisma Migrate**](https://www.prisma.io/docs/concepts/components/prisma-migrate): Declarative data modeling & migration system
- [**Prisma Studio**](https://github.com/prisma/studio): GUI to view and edit data in your databasePrisma Client can be used in _any_ Node.js or TypeScript backend application (including serverless applications and microservices). This can be a [REST API](https://www.prisma.io/docs/concepts/overview/prisma-in-your-stack/rest), a [GraphQL API](https://www.prisma.io/docs/concepts/overview/prisma-in-your-stack/graphql), a gRPC API, or anything else that needs a database.
If you need a database to use with Prisma ORM, check out [Prisma Postgres](https://www.prisma.io/docs/getting-started/quickstart-prismaPostgres?utm_source=github&utm_medium=org-readme).
**Prisma ORM can further be extended with these Prisma products:**
- [Prisma Accelerate](https://prisma.io/docs/data-platform/accelerate?utm_source=github&utm_medium=prisma-readme): Global database cache with scalable connection pooling
- [Prisma Pulse](https://www.prisma.io/docs/data-platform/pulse?utm_source=github&utm_medium=prisma-readme): Real-time database events with type-safe subscriptions
- [Prisma Optimize](https://www.prisma.io/docs/optimize?utm_source=github&utm_medium=prisma-readme): AI-powered query optimization and performance insights
- [Prisma Studio](https://www.prisma.io/docs/orm/tools/prisma-studio?utm_source=github&utm_medium=org-readme): A visual editor for the data in your database## 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:
- [Prisma Postgres](https://www.prisma.io/docs/getting-started/quickstart-prismaPostgres)
- [SQLite](https://www.prisma.io/docs/getting-started/quickstart-sqlite)### Bring your own database
If you already have your own database, you can follows these guides:
- [Add Prisma to an existing project](https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases-typescript-postgresql)
- [Set up a new project with Prisma from scratch](https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/relational-databases-typescript-postgresql)## 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](https://www.prisma.io/docs/).
### The Prisma schema
Every project that uses a tool from the Prisma toolkit starts with a [Prisma schema file](https://www.prisma.io/docs/concepts/components/prisma-schema). 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_:
```prisma
// 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](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/data-sources) and [Generators](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/generators) on the respective docs pages.
#### Functions of Prisma models
The data model is a collection of [models](https://www.prisma.io/docs/concepts/components/prisma-schema/data-model#defining-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](https://www.prisma.io/docs/concepts/components/introspection) a database
- Manually writing the data model and mapping it to the database with [Prisma Migrate](https://www.prisma.io/docs/concepts/components/prisma-migrate)Once the data model is defined, you can [generate Prisma Client](https://www.prisma.io/docs/concepts/components/prisma-client/generating-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"](https://www.prisma.io/docs/concepts/components/prisma-client/generating-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:
```ts
import { PrismaClient } from '@prisma/client'const prisma = new PrismaClient()
```or
```js
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](https://www.prisma.io/docs/concepts/components/prisma-client) or watch this [demo video](https://www.youtube.com/watch?v=LggrE5kJ75I&list=PLn2e1F9Rfr6k9PnR_figWOcSHgc_erDr5&index=4) (2 min).
##### Retrieve all `User` records from the database
```ts
// Run inside `async` function
const allUsers = await prisma.user.findMany()
```##### Include the `posts` relation on each returned `User` object
```ts
// Run inside `async` function
const allUsers = await prisma.user.findMany({
include: { posts: true },
})
```##### Filter all `Post` records that contain `"prisma"`
```ts
// 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
```ts
// 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
```ts
// 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](https://www.prisma.io/docs/concepts/components/prisma-client/advanced-usage-of-generated-types) page in the docs.
## Community
Prisma has a large and supportive [community](https://www.prisma.io/community) of enthusiastic application developers. You can join us on [Discord](https://pris.ly/discord) and here on [GitHub](https://github.com/prisma/prisma/discussions).
## Badges
[![Made with Prisma](http://made-with.prisma.io/dark.svg)](https://prisma.io) [![Made with Prisma](http://made-with.prisma.io/indigo.svg)](https://prisma.io)
Built something awesome with Prisma? 🌟 Show it off with these [badges](https://github.com/prisma/presskit?tab=readme-ov-file#badges), perfect for your readme or website.
```
[![Made with Prisma](http://made-with.prisma.io/dark.svg)](https://prisma.io)
``````
[![Made with Prisma](http://made-with.prisma.io/indigo.svg)](https://prisma.io)
```## Security
If you have a security issue to report, please contact us at [[email protected]](mailto:[email protected]?subject=[GitHub]%20Prisma%202%20Security%20Report%20).
## Support
### Ask a question about Prisma
You can ask questions and initiate [discussions](https://github.com/prisma/prisma/discussions/) about Prisma-related topics in the `prisma` repository on GitHub.
👉 [**Ask a question**](https://github.com/prisma/prisma/discussions/new)
### 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](https://www.prisma.io/docs/guides/other/troubleshooting-orm/creating-bug-reports) (like including additional debugging output) in the docs.
👉 [**Create bug report**](https://pris.ly/prisma-prisma-bug-report)
### Submit a feature request
If Prisma currently doesn't have a certain feature, be sure to check out the [roadmap](https://www.prisma.io/docs/more/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**](https://github.com/prisma/prisma/issues/new?assignees=&labels=&template=feature_request.md&title=)
## Contributing
Refer to our [contribution guidelines](https://github.com/prisma/prisma/blob/main/CONTRIBUTING.md) and [Code of Conduct for contributors](https://github.com/prisma/prisma/blob/main/CODE_OF_CONDUCT.md).
## Tests Status
- Prisma Tests Status:
[![Prisma Tests Status](https://github.com/prisma/prisma/workflows/CI/badge.svg)](https://github.com/prisma/prisma/actions/workflows/test.yml?query=branch%3Amain)
- Ecosystem Tests Status:
[![Ecosystem Tests Status](https://github.com/prisma/ecosystem-tests/workflows/test/badge.svg)](https://github.com/prisma/ecosystem-tests/actions/workflows/test.yaml?query=branch%3Adev)