Library cheatsheet
Prisma ORM Cheatsheet
Model your database in a schema, run migrations, and query with the type-safe Prisma Client. Examples use the prisma-client-js generator; check the docs for newer generators.
CLI and migrations
- Install Prisma — Add the CLI as a development dependency and the client as a dependency.
- Initialize Prisma — Create a prisma folder with schema.prisma and a .env file for DATABASE_URL.
- Create and apply a migration — Turn schema changes into a SQL migration and apply it to the development database.
- Apply migrations in production — Apply pending migrations without creating new ones. Use it in CI and deployments.
- Generate the client — Regenerate the client after changing the schema.
- Browse data in a UI — Open Prisma Studio in the browser to view and edit rows.
- Sync the schema without migrations — Push the schema straight to the database. Good for prototyping, not for production history.
- Introspect an existing database — Create or update the schema from a database that already exists.
- Reset the development database — Drop the database, recreate it and re-apply all migrations.
- Validate and format the schema — Check the schema for errors and format it.
Schema
- Configure the database — Choose the database provider and read the connection string from an environment variable.
- Define models — A model becomes a table. @id marks the primary key, @default sets defaults and @unique adds a unique index.
- Define a relation — A one-to-many relation uses a foreign key field and a @relation attribute.
- Composite keys and unique constraints — Use block attributes for keys and constraints that span several fields.
Prisma Client queries
- Create the client — Create one PrismaClient and reuse it, rather than a new one per request.
- Create a record — Insert a row and get it back, including generated fields.
- Create related records together — Create a user and their posts in one nested write.
- Find many with filters — Filter, sort and paginate.
- Find one by a unique field — Look up a record by id or unique field. It returns null if nothing matches.
- Include relations or pick fields — include loads related records, and select returns only the fields you name.
- Update a record — Change fields of one record.
- Update or create — Update the record if it exists, otherwise create it.
- Delete records — Delete one record, or many with a filter.
- Count and aggregate — Count rows and compute statistics.
- Group rows — Group by a field and count each group.
- Run several operations atomically — All operations succeed together or none are applied.
- Run raw SQL safely — Use the tagged template, which sends values as parameters and prevents SQL injection.
Related cheatsheets
- Hugging Face cheatsheet — The hf command line, and Transformers and Datasets code for downloading, running, training and sharing models.
- Matplotlib and seaborn 3 cheatsheet — Draw line, scatter, bar and histogram charts with Matplotlib, and statistical charts with seaborn.
- pandas and NumPy 3 cheatsheet — Load, clean, reshape, group and analyze tabular data with pandas, and work with arrays in NumPy.
- Polars 2 cheatsheet — Fast DataFrames in Python: expressions, filtering, grouping, joins, lazy queries and file formats.
- PyTorch 2 cheatsheet — Tensors, autograd, models, training loops, saving and speed-ups in PyTorch 2.
- React 19 cheatsheet — Hooks, components and patterns for React 19 in TypeScript or JavaScript.