======================== CODE SNIPPETS ======================== TITLE: Install Prisma Optimize Client Extension DESCRIPTION: This command installs the necessary npm packages for Prisma Client and the Prisma Optimize extension, allowing you to integrate Optimize into your application. SOURCE: https://github.com/prisma/docs/blob/main/content/700-optimize/200-getting-started.mdx#_snippet_0 LANGUAGE: bash CODE: ``` npm install @prisma/client@latest @prisma/extension-optimize ``` ---------------------------------------- TITLE: Download Prisma Example Project with try-prisma DESCRIPTION: This command uses `npx try-prisma` to download and set up a new Prisma project based on the `databases/prisma-postgres` template, naming it `hello-prisma` and installing dependencies using npm. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/01-quickstart-prismaPostgres.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` npx try-prisma@latest \ --template databases/prisma-postgres \ --name hello-prisma \ --install npm ``` ---------------------------------------- TITLE: Installing Dependencies and Starting Prisma Docs Locally DESCRIPTION: These commands are used to set up the local development environment for the Prisma documentation. First, `npm install` downloads all necessary project dependencies, and then `npm run start` launches the development server, making the documentation accessible via a web browser, typically at `http://localhost:3000`. SOURCE: https://github.com/prisma/docs/blob/main/README.md#_snippet_0 LANGUAGE: npm CODE: ``` npm install npm run start ``` ---------------------------------------- TITLE: Initialize Prisma Postgres Project DESCRIPTION: This command initializes a new Prisma project configured for a Postgres database, setting up the necessary files and configurations to get started with Prisma Postgres. SOURCE: https://github.com/prisma/docs/blob/main/content/250-postgres/100-introduction/200-getting-started.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` npx prisma init --db ``` ---------------------------------------- TITLE: Creating Project Directory DESCRIPTION: This command sequence creates a new directory named `hello-prisma` and then navigates into it, establishing the initial project workspace for the quickstart guide. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/01-quickstart-sqlite.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` mkdir hello-prisma cd hello-prisma ``` ---------------------------------------- TITLE: Install Core TanStack Start and Vinxi Dependencies DESCRIPTION: Installs the primary packages required for a TanStack Start application, including `@tanstack/react-start`, `@tanstack/react-router`, and `vinxi`, which are fundamental for the framework's operation. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/160-tanstack-start.mdx#_snippet_3 LANGUAGE: terminal CODE: ``` npm install @tanstack/react-start @tanstack/react-router vinxi ``` ---------------------------------------- TITLE: Installing Prisma Client and Accelerate Extension (Terminal) DESCRIPTION: This terminal command installs the latest versions of `@prisma/client` and `@prisma/extension-accelerate`. These packages are essential prerequisites for integrating and utilizing Prisma Accelerate within your Node.js application. SOURCE: https://github.com/prisma/docs/blob/main/content/300-accelerate/200-getting-started.mdx#_snippet_4 LANGUAGE: terminal CODE: ``` npm install @prisma/client@latest @prisma/extension-accelerate ``` ---------------------------------------- TITLE: Installing Prisma Client Package - Terminal DESCRIPTION: Installs the `@prisma/client` package, which is necessary to interact with the database using Prisma. This command also triggers `prisma generate` to create a tailored Prisma Client based on the schema. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/01-quickstart-sqlite.mdx#_snippet_7 LANGUAGE: terminal CODE: ``` npm install @prisma/client ``` ---------------------------------------- TITLE: Installing Prisma CLI DESCRIPTION: This command installs the Prisma CLI as a development dependency in your project, which is essential for managing your Prisma setup, including schema migrations and client generation. The second command verifies the installation. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/200-prisma-client/000-setup-and-configuration/005-introduction.mdx#_snippet_1 LANGUAGE: bash CODE: ``` npm install prisma --save-dev npx prisma ``` ---------------------------------------- TITLE: Combine Prisma Optimize with Accelerate Extension DESCRIPTION: This example illustrates the correct order for applying Prisma extensions when using both Optimize and Accelerate, ensuring Accelerate is applied after Optimize to avoid conflicts. SOURCE: https://github.com/prisma/docs/blob/main/content/700-optimize/200-getting-started.mdx#_snippet_4 LANGUAGE: typescript CODE: ``` const prisma = new PrismaClient().$extends(withOptimize()).$extends(withAccelerate()) ``` ---------------------------------------- TITLE: Example `npm` Installation Command DESCRIPTION: This snippet provides a practical example of installing a package using `npm` within a `terminal` code block. It reinforces the guideline to use `npm` as the default package manager in documentation examples. SOURCE: https://github.com/prisma/docs/blob/main/content/600-about/20-style-guide/03-spelling-punctuation-formatting.mdx#_snippet_8 LANGUAGE: Terminal CODE: ``` npm install prisma ``` ---------------------------------------- TITLE: Initializing Node.js and Installing TypeScript Dependencies DESCRIPTION: Initializes a new Node.js project with default settings using `npm init -y` and then installs `typescript`, `tsx`, and `@types/node` as development dependencies, preparing the project for TypeScript development. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/01-quickstart-sqlite.mdx#_snippet_1 LANGUAGE: terminal CODE: ``` npm init -y npm install typescript tsx @types/node --save-dev ``` ---------------------------------------- TITLE: Navigate, install dependencies, and start SolidStart dev server DESCRIPTION: Changes directory into the new project, installs Node.js dependencies, and starts the development server. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/180-solid-start.mdx#_snippet_1 LANGUAGE: terminal CODE: ``` cd my-solid-prisma-app npm install npm run dev ``` ---------------------------------------- TITLE: Configure Prisma Optimize API Key in .env DESCRIPTION: This snippet shows how to add your generated Prisma Optimize API key to your .env file, making it accessible to your application for authentication with the Optimize service. SOURCE: https://github.com/prisma/docs/blob/main/content/700-optimize/200-getting-started.mdx#_snippet_2 LANGUAGE: bash CODE: ``` OPTIMIZE_API_KEY="YOUR_OPTIMIZE_API_KEY" ``` ---------------------------------------- TITLE: Install Prisma and TSX Dependencies DESCRIPTION: These commands install the necessary npm packages for using Prisma in your project. `prisma` and `tsx` are installed as development dependencies, while `@prisma/extension-accelerate` and `@prisma/client` are core runtime dependencies for interacting with the database. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/160-tanstack-start.mdx#_snippet_15 LANGUAGE: terminal CODE: ``` npm install prisma tsx --save-dev npm install @prisma/extension-accelerate @prisma/client ``` LANGUAGE: terminal CODE: ``` npm install prisma tsx --save-dev npm install @prisma/client ``` ---------------------------------------- TITLE: Installing Prisma CLI as Development Dependency DESCRIPTION: Installs the Prisma Command Line Interface (CLI) as a development dependency in the project. The Prisma CLI provides essential tools for managing Prisma projects, including schema migrations, client generation, and database introspection. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/01-quickstart-sqlite.mdx#_snippet_3 LANGUAGE: terminal CODE: ``` npm install prisma --save-dev ``` ---------------------------------------- TITLE: Start Nuxt Development Server DESCRIPTION: Starts the Nuxt development server. This action triggers several automated steps, including Prisma CLI installation, Prisma project initialization with SQLite, creation of example Prisma models, and prompts for database migration. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/800-more/600-help-and-troubleshooting/900-prisma-nuxt-module.mdx#_snippet_2 LANGUAGE: terminal CODE: ``` npm run dev ``` ---------------------------------------- TITLE: Install React, Vite, and TypeScript Development Dependencies DESCRIPTION: Installs React and React DOM for UI development, along with development dependencies such as `@vitejs/plugin-react`, `vite-tsconfig-paths`, `typescript`, and their respective type definitions, crucial for a modern React setup. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/160-tanstack-start.mdx#_snippet_4 LANGUAGE: terminal CODE: ``` npm install react react-dom npm install --save-dev @vitejs/plugin-react vite-tsconfig-paths npm install --save-dev typescript @types/react @types/react-dom ``` ---------------------------------------- TITLE: Initializing Node.js Project and Installing Prisma CLI (Terminal) DESCRIPTION: This snippet initializes a new Node.js project with default settings using `npm init -y` and then installs the Prisma CLI as a development dependency. This sets up the basic Node.js environment and adds Prisma for development tasks, creating a `package.json` file. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb-node-mongodb.mdx#_snippet_1 LANGUAGE: terminal CODE: ``` npm init -y npm install prisma --save-dev ``` ---------------------------------------- TITLE: Install Prisma Dependencies for Postgres DESCRIPTION: Installs Prisma, tsx, and Prisma Accelerate client for use with PostgreSQL databases, including development dependencies. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/999-making-guides.mdx#_snippet_5 LANGUAGE: terminal CODE: ``` npm install prisma tsx --save-dev npm install @prisma/extension-accelerate @prisma/client ``` ---------------------------------------- TITLE: Prisma Client Initialization in TypeScript DESCRIPTION: This example demonstrates how to import and initialize the Prisma Client within a TypeScript file. It showcases the basic setup required to interact with your database using Prisma ORM, including necessary imports and instantiation of the client. The snippet also includes a file path metadata comment for context. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/999-making-guides.mdx#_snippet_1 LANGUAGE: TypeScript CODE: ``` // Import required dependencies import { PrismaClient } from '@prisma/client' // Initialize Prisma Client const prisma = new PrismaClient() ``` ---------------------------------------- TITLE: Extend Prisma Client with Optimize Extension DESCRIPTION: This TypeScript code demonstrates how to extend an existing Prisma Client instance with the `withOptimize` extension, passing the API key for integration with Prisma Optimize. SOURCE: https://github.com/prisma/docs/blob/main/content/700-optimize/200-getting-started.mdx#_snippet_3 LANGUAGE: typescript CODE: ``` import { PrismaClient } from "@prisma/client"; import { withOptimize } from "@prisma/extension-optimize"; const prisma = new PrismaClient().$extends( withOptimize({ apiKey: process.env.OPTIMIZE_API_KEY }), ); ``` ---------------------------------------- TITLE: Combine Prisma Optimize with Middleware DESCRIPTION: This snippet shows the recommended order for integrating Prisma Middleware with the Optimize extension, ensuring middleware is applied before any client extensions. SOURCE: https://github.com/prisma/docs/blob/main/content/700-optimize/200-getting-started.mdx#_snippet_5 LANGUAGE: typescript CODE: ``` const prisma = new PrismaClient().$use(middleware).$extends(withOptimize()) ``` ---------------------------------------- TITLE: Install Prisma Dependencies for Other Databases DESCRIPTION: Installs Prisma, tsx, and the core Prisma client for use with various database types, including development dependencies. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/999-making-guides.mdx#_snippet_6 LANGUAGE: terminal CODE: ``` npm install prisma tsx --save-dev npm install @prisma/client ``` ---------------------------------------- TITLE: Install Prisma Optimize Extension DESCRIPTION: This command installs the `@prisma/extension-optimize` package, which is required to use Prisma Optimize with your Prisma Client instance. It's a necessary dependency for integrating query optimization features. SOURCE: https://github.com/prisma/docs/blob/main/content/250-postgres/400-query-optimization/100-setup.mdx#_snippet_0 LANGUAGE: bash CODE: ``` npm install @prisma/extension-optimize ``` ---------------------------------------- TITLE: Installing Node.js Dependencies DESCRIPTION: This command installs all required Node.js packages and dependencies listed in the `package.json` file for the Prisma Koyeb example application, preparing it for execution. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/200-prisma-client/500-deployment/101-traditional/250-deploy-to-koyeb.mdx#_snippet_2 LANGUAGE: Shell CODE: ``` npm install ``` ---------------------------------------- TITLE: Downloading and Setting Up Prisma Heroku Example DESCRIPTION: This command sequence creates a new directory, navigates into it, and then downloads and extracts the Prisma Heroku example project from GitHub. This sets up the initial codebase for deployment. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/200-prisma-client/500-deployment/101-traditional/200-deploy-to-heroku.mdx#_snippet_0 LANGUAGE: Shell CODE: ``` mkdir prisma-heroku cd prisma-heroku curl https://codeload.github.com/prisma/prisma-examples/tar.gz/latest | tar -xz --strip=3 prisma-examples-latest/deployment-platforms/heroku ``` ---------------------------------------- TITLE: Downloading Prisma Example Application for Fly.io Deployment (Terminal) DESCRIPTION: This command sequence downloads and extracts the Prisma example application from GitHub, specifically the 'render' deployment platform example. It prepares the local environment by navigating into the extracted project directory, making it ready for further configuration and deployment on Fly.io. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/200-prisma-client/500-deployment/101-traditional/300-deploy-to-flyio.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` curl https://codeload.github.com/prisma/prisma-examples/tar.gz/latest | tar -xz --strip=2 prisma-examples-latest/deployment-platforms/render cd render ``` ---------------------------------------- TITLE: Initializing Node.js Project and Installing Dependencies DESCRIPTION: These commands initialize a new Node.js project with default settings (`npm init -y`) and then install `prisma`, `typescript`, `tsx`, and `@types/node` as development dependencies, which are essential for building a TypeScript application with Prisma. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb-typescript-mongodb.mdx#_snippet_1 LANGUAGE: terminal CODE: ``` npm init -y npm install prisma typescript tsx @types/node --save-dev ``` ---------------------------------------- TITLE: Install Prisma Client Extensions via npm DESCRIPTION: This snippet demonstrates how to install a published Prisma Client extension using npm. It provides the general command and a specific example for `prisma-extension-find-or-create`. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/200-prisma-client/300-client-extensions/140-shared-extensions/index.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` npm install prisma-extension- ``` LANGUAGE: terminal CODE: ``` npm install prisma-extension-find-or-create ``` ---------------------------------------- TITLE: Initializing Prisma Query Examples with a Constant in TypeScript DESCRIPTION: This TypeScript code snippet illustrates the recommended practice of starting Prisma query examples with a constant. This provides a clear noun for subsequent references within the documentation, enhancing clarity and readability of the example. SOURCE: https://github.com/prisma/docs/blob/main/content/600-about/20-style-guide/01-writing-style.mdx#_snippet_1 LANGUAGE: TypeScript CODE: ``` const aggregations = await prisma.user.aggregate({ ... }) ``` ---------------------------------------- TITLE: Downloading Prisma Koyeb Example Application DESCRIPTION: This command sequence creates a new directory, navigates into it, and then downloads and extracts the Prisma Koyeb example application from GitHub, stripping the top-level directory to place contents directly in the current folder. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/200-prisma-client/500-deployment/101-traditional/250-deploy-to-koyeb.mdx#_snippet_0 LANGUAGE: Shell CODE: ``` mkdir prisma-on-koyeb cd prisma-on-koyeb curl https://github.com/koyeb/example-prisma/tarball/main/latest | tar xz --strip=1 ``` ---------------------------------------- TITLE: Applying Prisma Middleware Before Accelerate Extension (TypeScript) DESCRIPTION: This example demonstrates the correct order for integrating Prisma Middleware with Prisma Client extensions. Middleware should always be applied using `$use()` before any extensions are applied with `$extends()`, ensuring that the middleware intercepts queries before they are processed by extensions like `withAccelerate`. SOURCE: https://github.com/prisma/docs/blob/main/content/300-accelerate/200-getting-started.mdx#_snippet_12 LANGUAGE: typescript CODE: ``` const prisma = new PrismaClient().$use(middleware).$extends(withAccelerate()) ``` ---------------------------------------- TITLE: Writing UI Steps: Bad vs. Good Examples (Markdown) DESCRIPTION: This snippet illustrates the difference between poorly written and well-written UI documentation steps. Good steps start with a clear, instructive verb and focus on a single action, avoiding passive descriptions of outcomes. SOURCE: https://github.com/prisma/docs/blob/main/content/600-about/20-style-guide/07-user-interace-guidelines.mdx#_snippet_0 LANGUAGE: md CODE: ``` The status changes to **Completed**. From **Status**, select **Completed**. ``` ---------------------------------------- TITLE: Configuring Prisma Schema with Accelerate URL (Prisma) DESCRIPTION: This Prisma schema snippet shows how the `DATABASE_URL` environment variable, now configured with the Accelerate connection string, is referenced in the `datasource` block. This setup directs Prisma Client to use the Accelerate endpoint for all database operations. SOURCE: https://github.com/prisma/docs/blob/main/content/300-accelerate/200-getting-started.mdx#_snippet_1 LANGUAGE: prisma CODE: ``` datasource db { provider = "postgresql" url = env("DATABASE_URL") } ``` ---------------------------------------- TITLE: Example of a Real Database Connection URL in Prisma Schema DESCRIPTION: This snippet provides an example of a 'real value' for a database connection URL in a Prisma schema, replacing the placeholder. It demonstrates what a production-ready connection string might look like, including credentials and host details, to guide users on expected input. SOURCE: https://github.com/prisma/docs/blob/main/content/600-about/20-style-guide/03-spelling-punctuation-formatting.mdx#_snippet_2 LANGUAGE: prisma CODE: ``` datasource db { provider = "postgresql" url = "postgresql://opnmyfngbknppm:XXX@ec2-46-137-91-216.eu-west-1.compute.amazonaws.com:5432/d50rgmkqi2ipus?schema=hello-prisma2" } ``` ---------------------------------------- TITLE: Rename Environment Example File DESCRIPTION: This command renames the `.env.example` file to `.env`, making it the active environment configuration file for the project. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/01-quickstart-prismaPostgres.mdx#_snippet_2 LANGUAGE: terminal CODE: ``` mv .env.example .env ``` ---------------------------------------- TITLE: Initialize TanStack Start Project Directory DESCRIPTION: Creates a new directory for the TanStack Start project, navigates into it, and initializes a new Node.js project using npm's default settings. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/160-tanstack-start.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` mkdir tanstack-start-prisma cd tanstack-start-prisma npm init -y ``` ---------------------------------------- TITLE: Creating and Navigating Project Directory (Terminal) DESCRIPTION: This snippet demonstrates how to create a new project directory named `hello-prisma` and then navigate into it using standard terminal commands. This is the essential first step for setting up a new project environment. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb-node-mongodb.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` mkdir hello-prisma cd hello-prisma ``` ---------------------------------------- TITLE: Enable Tracing Preview Feature in Prisma Schema DESCRIPTION: For older Prisma ORM versions (4.2.0 to 6.1.0), this Prisma schema configuration enables the "tracing" preview feature, which is required for Prisma Optimize functionality. SOURCE: https://github.com/prisma/docs/blob/main/content/700-optimize/200-getting-started.mdx#_snippet_1 LANGUAGE: prisma CODE: ``` generator client { provider = "prisma-client-js" previewFeatures = ["tracing"] } ``` ---------------------------------------- TITLE: Start Application Server for Testing DESCRIPTION: Command to start the local development server to test the application's functionality after database setup and migrations. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/130-docker.mdx#_snippet_14 LANGUAGE: bash CODE: ``` npm run dev ``` ---------------------------------------- TITLE: Creating Project Directory and Navigating (Terminal) DESCRIPTION: This snippet demonstrates the initial steps to set up a new project directory. It creates a folder named 'hello-prisma' and then changes the current working directory into it, preparing the environment for further project setup. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases-node-sqlserver.mdx#_snippet_0 LANGUAGE: Shell CODE: ``` mkdir hello-prisma cd hello-prisma ``` ---------------------------------------- TITLE: Creating Migration Directory for Prisma Baseline (Terminal) DESCRIPTION: This command creates a new directory, `0_init`, inside `prisma/migrations`. This directory will house the initial baseline migration files, ensuring that Prisma Migrate can track changes from a known starting point. The `0_` prefix is crucial for lexicographical ordering, allowing it to be applied first. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/300-prisma-migrate/050-getting-started.mdx#_snippet_7 LANGUAGE: terminal CODE: ``` mkdir -p prisma/migrations/0_init ``` ---------------------------------------- TITLE: Create Essential TanStack Start Application Files and Directories DESCRIPTION: Creates the necessary `app` directory and its subdirectories, along with core files like `router.tsx`, `ssr.tsx`, `client.tsx`, `__root.tsx`, and `index.tsx`, which are fundamental for establishing the TanStack Start project structure. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/160-tanstack-start.mdx#_snippet_7 LANGUAGE: terminal CODE: ``` mkdir app touch app/router.tsx touch app/ssr.tsx touch app/client.tsx mkdir app/routes touch app/routes/__root.tsx touch app/routes/index.tsx ``` ---------------------------------------- TITLE: Installing Prisma Client Package DESCRIPTION: This command installs the Prisma Client library, which is the auto-generated and type-safe query builder used to interact with your database from your application code. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/200-prisma-client/000-setup-and-configuration/005-introduction.mdx#_snippet_2 LANGUAGE: bash CODE: ``` npm install @prisma/client ``` ---------------------------------------- TITLE: Initialize Prisma Project DESCRIPTION: Initializes Prisma in the current project, setting up the database connection and specifying the output path for the generated Prisma Client. Users will be prompted for database details. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/999-making-guides.mdx#_snippet_7 LANGUAGE: terminal CODE: ``` npx prisma init --db --output ../generated/prisma ``` ---------------------------------------- TITLE: Installing Node.js Dependencies for Prisma Heroku Project DESCRIPTION: This command installs all required Node.js packages and dependencies for the Prisma Heroku example application, as specified in the `package.json` file. This is a crucial step before running or deploying the application. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/200-prisma-client/500-deployment/101-traditional/200-deploy-to-heroku.mdx#_snippet_2 LANGUAGE: npm CODE: ``` npm install ``` ---------------------------------------- TITLE: Get Post records where title starts with 'Pr' using startsWith DESCRIPTION: This example shows the `startsWith` operator, used to filter records where a string field's value begins with the specified substring. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/500-reference/050-prisma-client-reference.mdx#_snippet_182 LANGUAGE: js CODE: ``` const result = await prisma.post.findMany({ where: { title: { startsWith: 'Pr', }, }, }); ``` ---------------------------------------- TITLE: Install Fig for Prisma CLI Autocompletion DESCRIPTION: This command installs `Fig` using Homebrew. Fig provides autocompletion for the Prisma CLI and works in bash, zsh, and fish shells. `inshellisense` is built on top of Fig. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/800-more/500-development-environment/200-editor-setup.mdx#_snippet_3 LANGUAGE: bash CODE: ``` brew install fig ``` ---------------------------------------- TITLE: Generating Prisma Client with Accelerate Option (Prisma < 5.2.0) DESCRIPTION: For Prisma versions older than `5.2.0`, this command is used to generate the Prisma Client with explicit support for Prisma Accelerate. This flag ensures the client is configured to connect via the Accelerate service. SOURCE: https://github.com/prisma/docs/blob/main/content/300-accelerate/200-getting-started.mdx#_snippet_7 LANGUAGE: terminal CODE: ``` npx prisma generate --accelerate ``` ---------------------------------------- TITLE: Initializing Node.js Project and Installing Prisma CLI (npm) DESCRIPTION: This snippet initializes a new Node.js project with default settings using `npm init -y` and then installs the Prisma CLI as a development dependency using `npm install prisma --save-dev`. This prepares the project for Prisma ORM integration. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases-node-postgresql.mdx#_snippet_1 LANGUAGE: Shell CODE: ``` npm init -y npm install prisma --save-dev ``` ---------------------------------------- TITLE: Installing Prisma Client Package DESCRIPTION: This command installs the `@prisma/client` package, which is the core library for interacting with your database using Prisma. It's a prerequisite for generating and using the Prisma Client. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/_install-prisma-client-partial.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` npm install @prisma/client ``` ---------------------------------------- TITLE: Initialize Prisma Client Globally DESCRIPTION: Demonstrates how to create a single, globally accessible Prisma Client instance. It includes two variations: one for PostgreSQL with Prisma Accelerate for connection pooling, and another for other databases without Accelerate. This setup prevents multiple client instantiations and manages database connections efficiently. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/160-tanstack-start.mdx#_snippet_23 LANGUAGE: tsx CODE: ``` import { PrismaClient } from "../generated/prisma/client.js"; import { withAccelerate } from "@prisma/extension-accelerate"; const prisma = new PrismaClient().$extends(withAccelerate()); export default prisma; ``` LANGUAGE: tsx CODE: ``` import { PrismaClient } from "../generated/prisma/client.js"; const prisma = new PrismaClient(); export default prisma; ``` ---------------------------------------- TITLE: Open Prisma Studio GUI DESCRIPTION: Command to launch Prisma Studio, a built-in graphical user interface for viewing and editing database data with Prisma ORM. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/01-quickstart-prismaPostgres.mdx#_snippet_10 LANGUAGE: terminal CODE: ``` npx prisma studio ``` ---------------------------------------- TITLE: Creating Project Directory and Navigating (Shell) DESCRIPTION: This snippet creates a new directory named `hello-prisma` for the project and then changes the current working directory into it. This is the initial setup step for any new Node.js project. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases-node-postgresql.mdx#_snippet_0 LANGUAGE: Shell CODE: ``` mkdir hello-prisma cd hello-prisma ``` ---------------------------------------- TITLE: Viewing Application Runtime Logs - Node.js DESCRIPTION: This snippet shows example runtime logs from a Node.js application deployed on Koyeb. It indicates the application's start command, confirms the server is ready, and provides a URL for sample requests, useful for debugging and monitoring. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/200-prisma-client/500-deployment/101-traditional/250-deploy-to-koyeb.mdx#_snippet_7 LANGUAGE: shell CODE: ``` node-72d14691 stdout > prisma-koyeb@1.0.0 start node-72d14691 stdout > node src/index.js node-72d14691 stdout 🚀 Server ready at: http://localhost:8080 node-72d14691 stdout ⭐️ See sample requests: http://pris.ly/e/ts/rest-express#3-using-the-rest-api ``` ---------------------------------------- TITLE: Run Nuxt Development Server for New Database Setup DESCRIPTION: Starts the Nuxt development server. For a new database setup, this command will prompt the user to migrate schema changes to the database and to install/access Prisma Studio from Nuxt Devtools, facilitating initial database synchronization. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/800-more/600-help-and-troubleshooting/900-prisma-nuxt-module.mdx#_snippet_8 LANGUAGE: terminal CODE: ``` npm run dev ``` ---------------------------------------- TITLE: Install inshellisense for Prisma CLI Autocompletion DESCRIPTION: This command installs `inshellisense` globally using npm. `inshellisense` provides IDE-style autocompletion for the Prisma CLI in various shells like bash, zsh, fish, and PowerShell. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/800-more/500-development-environment/200-editor-setup.mdx#_snippet_2 LANGUAGE: bash CODE: ``` npm install -g @microsoft/inshellisense ``` ---------------------------------------- TITLE: Prisma ORM Integration Guide Template (MDX) DESCRIPTION: This comprehensive Markdown template provides a standardized structure for creating new Prisma ORM integration guides in `.mdx` files. It includes front matter for metadata, a developer checklist for content validation, and predefined sections for introduction, prerequisites, and setup, promoting consistency across documentation. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/999-making-guides.mdx#_snippet_4 LANGUAGE: markdown CODE: ``` --- title: 'How to use Prisma ORM with __________' metaTitle: 'How to use Prisma ORM and Prisma Postgres with __________' description: 'Learn how to use Prisma ORM in a __________ app' sidebar_label: '__________ with Prisma' image: '/img/guides/prisma-__________-cover.png' completion_time: '15 min' community_section: true --- :::warning DEVELOPER CHECKLIST - Remove upon completion - [ ] `CTRL or CMD + F` to find 10 `_`'s and replace them with the framework name. - [ ] Provide a brief overview of the guide's purpose and the benefits of integrating Prisma ORM with the specified framework. - [ ] Link to the official documentation of the framework upon its first mention in the Introduction section. - [ ] List all necessary or recommended prerequisites, including specific software versions and any required accounts or services. - [ ] Name project *framework*-prisma (ie. *__________*-prisma) - [ ] Project creation options should be detailed in an info admonition in this format: ```markdown markdown - *Which package manager would you like to use?* `npm` ``` - [ ] Ensure the appropriate admonitions (note, warning, tip) are used for important information. - [ ] Include links to related guides and resources throughout the content. - [ ] Instead of using `we, we'll, ours, etc.` use `you, you'll, yours, etc.` - [ ] All lines ending before a code block should end with a colon (This one -> `:`) ::: ## Introduction Prisma ORM streamlines database access with type-safe queries, and when paired with [__________](https://example.com/), it creates a... :::warning ***DEV NOTE:*** Above, briefly explain the benefits of using Prisma ORM with the specified framework after `it creates a...` ::: In this guide, you'll learn to integrate Prisma ORM with a Prisma Postgres database in a __________ project from scratch. You can find a complete example of this guide on [GitHub](https://github.com/prisma/prisma-examples/tree/latest/orm/__________). ## Prerequisites - [Node.js 18+](https://nodejs.org) ## 1. Set up your project ## 2. Install and Configure Prisma ``` ---------------------------------------- TITLE: Initialize Prisma Project DESCRIPTION: This command initializes Prisma in your project, setting up the basic directory structure and configuration files. It creates a `prisma` directory with `schema.prisma`, a `.env` file for the database URL, and specifies an output directory for the generated Prisma Client. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/160-tanstack-start.mdx#_snippet_16 LANGUAGE: terminal CODE: ``` npx prisma init --db --output ../app/generated/prisma ``` ---------------------------------------- TITLE: Installing and Making Mdtool Executable DESCRIPTION: These commands download the `mdtool` script from a Gist and make it executable, allowing it to be run as a command-line utility. `wget` fetches the script, saving it to `/usr/local/bin/mdtool`, and `chmod +x` grants execute permissions, enabling its use for managing documentation file prefixes. SOURCE: https://github.com/prisma/docs/blob/main/README.md#_snippet_4 LANGUAGE: bash CODE: ``` wget https://gist.githubusercontent.com/steebchen/bd085ebde1fcf4242e3fdd0df4d202a6/raw/c04e3d262eb6a302a9fab98f6428fec9329681e2/mdtool -qO /usr/local/bin/mdtool chmod +x /usr/local/bin/mdtool ``` ---------------------------------------- TITLE: Generating Prisma Client for Serverless/Edge Applications (Terminal) DESCRIPTION: This command generates the Prisma Client specifically for serverless or edge environments. The `--no-engine` flag is crucial as it prevents the inclusion of the Query Engine file, significantly reducing the application's bundle size, which is beneficial for cold start times and deployment limits in these environments. SOURCE: https://github.com/prisma/docs/blob/main/content/300-accelerate/200-getting-started.mdx#_snippet_6 LANGUAGE: terminal CODE: ``` npx prisma generate --no-engine ``` ---------------------------------------- TITLE: Local PostgreSQL Connection URL Example (macOS) DESCRIPTION: This snippet illustrates a `DATABASE_URL` example for a PostgreSQL database running locally on macOS. It shows how the user, password, and database name often default to the current OS user, simplifying local development setup. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/100-connect-your-database-typescript-postgresql.mdx#_snippet_4 LANGUAGE: bash CODE: ``` DATABASE_URL="postgresql://janedoe:janedoe@localhost:5432/janedoe?schema=hello-prisma" ``` ---------------------------------------- TITLE: Explore Database with Prisma Studio DESCRIPTION: Use this command to launch Prisma Studio, a visual tool that allows you to inspect and manage the records created in your database. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/01-quickstart-prismaPostgres.mdx#_snippet_6 LANGUAGE: terminal CODE: ``` npx prisma studio ``` ---------------------------------------- TITLE: Initializing Node.js Project and Installing Prisma CLI (Terminal) DESCRIPTION: This sequence initializes a new Node.js project with default settings, creating a `package.json` file, and then installs the Prisma CLI as a development dependency, making Prisma commands available for the project. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases-node-mysql.mdx#_snippet_1 LANGUAGE: terminal CODE: ``` npm init -y npm install prisma --save-dev ``` ---------------------------------------- TITLE: Multi-file Prisma Schema Directory Structure Example DESCRIPTION: Presents an example directory structure for a multi-file Prisma schema setup, showing a `prisma` folder containing `migrations`, a `models` directory with multiple `.prisma` files, and a main `schema.prisma` file. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/100-prisma-schema/10-overview/04-location.mdx#_snippet_3 LANGUAGE: plaintext CODE: ``` . ├── migrations ├── models │ ├── posts.prisma │ ├── users.prisma │ └── ... other `.prisma` files └── schema.prisma ``` ---------------------------------------- TITLE: Building and Serving Static Prisma Docs Site DESCRIPTION: These commands are essential for testing the production build of the Prisma documentation site. `npm run clean && npm run build` first removes any previous build artifacts and then compiles the static site, while `npm run serve` starts a local server to preview the generated static files. SOURCE: https://github.com/prisma/docs/blob/main/README.md#_snippet_1 LANGUAGE: npm CODE: ``` npm run clean && npm run build npm run serve ``` ---------------------------------------- TITLE: Setting Up Prisma ORM with SQLite Provider DESCRIPTION: Initializes Prisma ORM in the project, configuring SQLite as the database provider. The `--output` flag specifies a custom directory for the generated Prisma Client, and this command also creates the `prisma` directory with `schema.prisma`. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/01-quickstart-sqlite.mdx#_snippet_4 LANGUAGE: terminal CODE: ``` npx prisma init --datasource-provider sqlite --output ../generated/prisma ``` ---------------------------------------- TITLE: Generate Prisma Client without Query Engine DESCRIPTION: This command generates the Prisma Client for a Prisma Postgres project, explicitly excluding the query engine. This is recommended for Prisma Postgres as the engine is not required, optimizing the client size. SOURCE: https://github.com/prisma/docs/blob/main/content/250-postgres/100-introduction/200-getting-started.mdx#_snippet_1 LANGUAGE: terminal CODE: ``` prisma generate --no-engine ``` ---------------------------------------- TITLE: Creating Initial Migration with Prisma Migrate Dev DESCRIPTION: This command generates the first migration file named 'init' based on the current Prisma schema. It applies the schema changes to the development database and records the migration in the _migrations table, syncing the database with the schema. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/300-prisma-migrate/050-getting-started.mdx#_snippet_1 LANGUAGE: terminal CODE: ``` prisma migrate dev --name init ``` ---------------------------------------- TITLE: Running Initial Prisma Migration for Database Creation DESCRIPTION: Executes a development migration named 'init' using Prisma Migrate. This command creates the SQLite database file (`dev.db`), applies the schema changes to create the `User` and `Post` tables, and automatically runs `prisma generate` to update the Prisma Client. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/01-quickstart-sqlite.mdx#_snippet_6 LANGUAGE: terminal CODE: ``` npx prisma migrate dev --name init ``` ---------------------------------------- TITLE: Initialize TanStack Start Client-Side Application (app/client.tsx) DESCRIPTION: Initializes the client-side logic for the TanStack Start application in `client.tsx`, hydrating the React root and setting up the router to handle client-side navigation and interactions. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/160-tanstack-start.mdx#_snippet_10 LANGUAGE: typescript CODE: ``` import { hydrateRoot } from "react-dom/client"; import { StartClient } from "@tanstack/react-start/client"; import { createRouter } from "./router"; const router = createRouter(); hydrateRoot(document, ); ``` ---------------------------------------- TITLE: Example Local macOS PostgreSQL Connection URL DESCRIPTION: This snippet shows an example of a `DATABASE_URL` for a PostgreSQL database running locally on macOS. It typically uses the OS user's name for both user and password, and `localhost` for the host, demonstrating a common local development setup. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/100-connect-your-database-node-postgresql.mdx#_snippet_4 LANGUAGE: bash CODE: ``` DATABASE_URL="postgresql://janedoe:janedoe@localhost:5432/janedoe?schema=hello-prisma" ``` ---------------------------------------- TITLE: Run Prisma Database Migrations DESCRIPTION: This command applies the changes defined in your `schema.prisma` file to your database. It creates the `User` and `Post` tables and generates the Prisma Client based on the updated schema, ensuring your application's data models are synchronized with the database. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/160-tanstack-start.mdx#_snippet_18 LANGUAGE: terminal CODE: ``` npx prisma migrate dev --name init ``` ---------------------------------------- TITLE: Initialize Prisma Client and setup main function DESCRIPTION: This snippet demonstrates the initial setup for using Prisma Client in a Node.js application. It imports the PrismaClient constructor, instantiates it, defines an asynchronous `main` function for database queries, and includes error handling and disconnection logic. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases/250-querying-the-database-node-mysql.mdx#_snippet_0 LANGUAGE: javascript CODE: ``` const { PrismaClient } = require('./generated/prisma') const prisma = new PrismaClient() async function main() { // ... you will write your Prisma Client queries here } main() .then(async () => { await prisma.$disconnect() }) .catch(async (e) => { console.error(e) await prisma.$disconnect() process.exit(1) }) ``` ---------------------------------------- TITLE: Install Prisma and related dependencies DESCRIPTION: Install Prisma, `tsx`, `@prisma/extension-accelerate`, and `@prisma/client` for your project. The recommended setup includes `@prisma/extension-accelerate` for Prisma Postgres, while other databases only require `@prisma/client`. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/090-nextjs.mdx#_snippet_2 LANGUAGE: terminal CODE: ``` npm install prisma tsx --save-dev npm install @prisma/extension-accelerate @prisma/client ``` LANGUAGE: terminal CODE: ``` npm install prisma tsx --save-dev npm install @prisma/client ``` ---------------------------------------- TITLE: Initializing Prisma Project with Custom Output DESCRIPTION: This command initializes a new Prisma ORM project, creating a `prisma` directory with `schema.prisma` and an `.env` file. It specifies the database provider using `--datasource-provider` and sets a custom output location for generated files with `--output`. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/_prisma-init-partial.mdx#_snippet_1 LANGUAGE: terminal CODE: ``` npx prisma init --datasource-provider ${props.datasource.toLowerCase()} --output ../generated/prisma ``` ---------------------------------------- TITLE: Installing Prisma Client Package - Terminal DESCRIPTION: This command installs the `@prisma/client` package, which is the core library for interacting with your database using Prisma. It's a prerequisite for generating and using Prisma Client. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/_install-prisma-client-partial.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` npm install @prisma/client ``` ---------------------------------------- TITLE: Creating Project Directory and Navigating (Shell) DESCRIPTION: This snippet creates a new directory named `hello-prisma` for the project and then changes the current working directory into it. This is the initial step for setting up the project environment. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases-typescript-postgresql.mdx#_snippet_0 LANGUAGE: Shell CODE: ``` mkdir hello-prisma cd hello-prisma ``` ---------------------------------------- TITLE: Defining DATABASE_URL Environment Variable (macOS Local Example) DESCRIPTION: This snippet shows a `DATABASE_URL` example for a PostgreSQL database running locally on macOS. It assumes the username, password, and database name correspond to the current OS user, which is a common setup for local development. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/110-relational-databases/100-connect-your-database-typescript-postgresql.mdx#_snippet_4 LANGUAGE: bash CODE: ``` DATABASE_URL="postgresql://janedoe:janedoe@localhost:5432/janedoe?schema=hello-prisma" ``` ---------------------------------------- TITLE: Installing Wget for Mdtool on macOS DESCRIPTION: This command installs `wget`, a command-line utility for retrieving content from web servers, using Homebrew. `wget` is a prerequisite for installing `mdtool`, a specialized CLI tool designed to manage the prefixed MDX files in the Prisma documentation. SOURCE: https://github.com/prisma/docs/blob/main/README.md#_snippet_3 LANGUAGE: bash CODE: ``` brew install wget ``` ---------------------------------------- TITLE: Creating Project Directory and Navigating (Terminal) DESCRIPTION: This snippet demonstrates how to create a new project directory named `hello-prisma` and then navigate into it using standard terminal commands. This is the initial step for setting up a new development environment. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases-typescript-mysql.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` mkdir hello-prisma cd hello-prisma ``` ---------------------------------------- TITLE: Install Prisma and related dependencies DESCRIPTION: Installs Prisma, `tsx`, `@prisma/extension-accelerate`, and `@prisma/client` for database interaction, with separate commands for Prisma Postgres and other databases. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/180-solid-start.mdx#_snippet_3 LANGUAGE: terminal CODE: ``` npm install prisma tsx --save-dev npm install @prisma/extension-accelerate @prisma/client ``` LANGUAGE: terminal CODE: ``` npm install prisma tsx --save-dev npm install @prisma/client ``` ---------------------------------------- TITLE: Initializing Node.js Project and Installing Prisma CLI (NPM) DESCRIPTION: This snippet initializes a new Node.js project with default settings and installs the Prisma CLI as a development dependency. This prepares the Node.js application and makes the Prisma command-line tools available for use in the project. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases-node-sqlserver.mdx#_snippet_1 LANGUAGE: Shell CODE: ``` npm init -y npm install prisma --save-dev ``` ---------------------------------------- TITLE: Opening Prisma Studio (Terminal) DESCRIPTION: This command launches Prisma Studio, a graphical user interface provided by Prisma ORM. It allows developers to view and edit data directly in their database, providing a convenient way to inspect the database state. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/01-quickstart-sqlite.mdx#_snippet_22 LANGUAGE: terminal CODE: ``` npx prisma studio ``` ---------------------------------------- TITLE: Install Prisma ORM and Initialize Project DESCRIPTION: Commands to install the latest Prisma ORM packages and initialize a new Prisma project with MongoDB as the datasource provider. This process creates the initial `prisma/schema.prisma` and `.env` files. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/08-upgrade-from-mongodb-beta.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` npm install prisma@latest && npm install @prisma/client npx prisma init --datasource-provider=mongodb ``` ---------------------------------------- TITLE: Set up project directory and initialize Prisma DESCRIPTION: Creates a new directory for the project and initializes a Prisma application using `npx prisma init --db`, connecting the CLI to Prisma Data Platform and setting up the `prisma` directory with `schema.prisma` and a `.env` file. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/200-prisma-client/500-deployment/301-edge/550-deploy-to-deno-deploy.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` mkdir prisma-deno-deploy cd prisma-deno-deploy npx prisma@latest init --db ``` ---------------------------------------- TITLE: Prisma CLI Command Output and Examples DESCRIPTION: This output provides a comprehensive overview of the Prisma CLI, listing its main commands, available flags, and practical examples for common operations like initializing a project, generating client, and managing database migrations. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/400-tools/05-prisma-cli.mdx#_snippet_13 LANGUAGE: terminal CODE: ``` Prisma is a modern DB toolkit to query, migrate and model your database (https://www.prisma.io) Usage $ prisma [command] Commands init Setup Prisma for your app generate Generate artifacts (e.g. Prisma Client) db Manage your database schema and lifecycle migrate Migrate your database studio Browse your data with Prisma Studio validate Validate your Prisma schema format Format your Prisma schema Flags --preview-feature Run Preview Prisma commands Examples Setup a new Prisma project $ prisma init Generate artifacts (e.g. Prisma Client) $ prisma generate Browse your data $ prisma studio Create migrations from your Prisma schema, apply them to the database, generate artifacts (e.g. Prisma Client) $ prisma migrate dev Pull the schema from an existing database, updating the Prisma schema $ prisma db pull Push the Prisma schema state to the database $ prisma db push ``` ---------------------------------------- TITLE: Starting Node.js Application on Render DESCRIPTION: This command is configured as the 'Start Command' for the web service on Render. It executes the script defined in the `package.json` file under the 'start' key, typically launching the main application server. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/200-prisma-client/500-deployment/101-traditional/225-deploy-to-render.mdx#_snippet_4 LANGUAGE: Shell CODE: ``` npm run start ``` ---------------------------------------- TITLE: Initializing Prisma Client Boilerplate - TypeScript DESCRIPTION: Provides the foundational TypeScript code for using Prisma Client. It imports `PrismaClient`, instantiates it, defines an asynchronous `main` function for queries, and includes error handling and disconnection logic to ensure proper resource management. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/01-quickstart-sqlite.mdx#_snippet_9 LANGUAGE: ts CODE: ``` import { PrismaClient } from './generated/prisma' const prisma = new PrismaClient() async function main() { // ... you will write your Prisma Client queries here } main() .then(async () => { await prisma.$disconnect() }) .catch(async (e) => { console.error(e) await prisma.$disconnect() process.exit(1) }) ``` ---------------------------------------- TITLE: Example MongoDB Connection String Format DESCRIPTION: A generic example of a MongoDB connection string, showing placeholders for user, password, host, and port. This format is essential for connecting to a MongoDB database. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/08-upgrade-from-mongodb-beta.mdx#_snippet_1 LANGUAGE: bash CODE: ``` mongodb://:@:27017 ``` ---------------------------------------- TITLE: Installing Prisma Client Package (npm) DESCRIPTION: This command installs the `@prisma/client` npm package, which is the core library for interacting with your database using Prisma. It's a prerequisite for generating and using Prisma Client. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/200-install-prisma-client-node-mongodb.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` npm install @prisma/client ``` ---------------------------------------- TITLE: Apply Prisma Client Extensions in Correct Order DESCRIPTION: When combining multiple Prisma Client extensions, their order of application matters as the last applied extension takes precedence. This example shows a typical order for `withOptimize` and `withAccelerate`. SOURCE: https://github.com/prisma/docs/blob/main/content/250-postgres/400-query-optimization/100-setup.mdx#_snippet_4 LANGUAGE: ts CODE: ``` const prisma = new PrismaClient().$extends(withOptimize()).$extends(withAccelerate()) ``` ---------------------------------------- TITLE: Run TanStack Start Development Server DESCRIPTION: This command starts the development server for the TanStack Start application. Executing this command will also generate the `routeTree.gen.ts` file, which is crucial for resolving routing errors and enabling type-safe routing. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/160-tanstack-start.mdx#_snippet_14 LANGUAGE: terminal CODE: ``` npm run dev ``` ---------------------------------------- TITLE: Extending Prisma Client with Accelerate Extension (TypeScript) DESCRIPTION: This TypeScript snippet demonstrates how to extend an existing `PrismaClient` instance with the `withAccelerate` extension. This extension integrates Prisma Accelerate's features, such as connection pooling and caching, into your Prisma Client instance, enabling its use in your application. SOURCE: https://github.com/prisma/docs/blob/main/content/300-accelerate/200-getting-started.mdx#_snippet_9 LANGUAGE: typescript CODE: ``` import { PrismaClient } from '@prisma/client' import { withAccelerate } from '@prisma/extension-accelerate' const prisma = new PrismaClient().$extends(withAccelerate()) ``` ---------------------------------------- TITLE: Installing Prisma Client and Prisma CLI DESCRIPTION: Installs the latest versions of `@prisma/client` and `prisma` packages, which are prerequisites for using TypedSQL in a Prisma project. `@prisma/client` is installed as a regular dependency, while `prisma` is installed as a development dependency. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/200-prisma-client/150-using-raw-sql/100-typedsql.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` npm install @prisma/client@latest npm install -D prisma@latest ``` ---------------------------------------- TITLE: Using 'clear' for Checkbox Actions (Markdown) DESCRIPTION: This snippet demonstrates the preferred term 'clear' for guiding readers to remove a check mark from a checkbox. It contrasts a 'Good' example using 'clear' with a 'Bad' example using 'deselect'. SOURCE: https://github.com/prisma/docs/blob/main/content/600-about/20-style-guide/02-word-choice.mdx#_snippet_9 LANGUAGE: md CODE: ``` Clear **Include sample data**. Deselect the **Include sample data** checkbox. ``` ---------------------------------------- TITLE: Install Application and Development Dependencies DESCRIPTION: Commands to install core application dependencies like Express, CORS, dotenv, and Prisma client, along with development dependencies such as Prisma, TypeScript, and tsx. It also initializes Prisma setup. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/320-permit-io-access-control.mdx#_snippet_1 LANGUAGE: terminal CODE: ``` npm install express cors dotenv @prisma/client npm install -D prisma typescript tsx npx prisma init ``` ---------------------------------------- TITLE: Run Prisma Database Migration to Create Tables DESCRIPTION: This Prisma CLI command creates and executes a schema migration named 'init'. It maps the `User` and `Post` models defined in your Prisma schema to corresponding tables in your database. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/01-quickstart-prismaPostgres.mdx#_snippet_4 LANGUAGE: terminal CODE: ``` npx prisma migrate dev --name init ``` ---------------------------------------- TITLE: Generating Initial Baseline Migration SQL (Terminal) DESCRIPTION: This command generates an initial SQL migration script by comparing an empty state to the current `prisma/schema.prisma`. The output is redirected to `prisma/migrations/0_init/migration.sql`, which serves as the baseline for the database's migration history. It assumes the database is empty for the purpose of generating the script. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/300-prisma-migrate/050-getting-started.mdx#_snippet_8 LANGUAGE: terminal CODE: ``` npx prisma migrate diff \ --from-empty \ --to-schema-datamodel prisma/schema.prisma \ --script > prisma/migrations/0_init/migration.sql ``` ---------------------------------------- TITLE: Define RootComponent and RootDocument in TanStack Start DESCRIPTION: This code defines the foundational React components for a TanStack Start application. `RootComponent` serves as the main entry point, rendering the `Outlet` for nested routes, while `RootDocument` sets up the basic HTML structure including head content and scripts. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/160-tanstack-start.mdx#_snippet_12 LANGUAGE: typescript CODE: ``` function RootComponent() { return ( ); } function RootDocument({ children }: Readonly<{ children: ReactNode }>) { return ( {children} ); } ``` ---------------------------------------- TITLE: Installing Prisma Accelerate Extension (Optional) DESCRIPTION: These commands optionally install the `@prisma/extension-accelerate` package, which is recommended when using Prisma with Postgres for enhanced performance. This dependency is not strictly required for basic Prisma setup but can optimize database interactions. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/080-turborepo.mdx#_snippet_5 LANGUAGE: npm CODE: ``` npm install @prisma/extension-accelerate ``` LANGUAGE: yarn CODE: ``` yarn add @prisma/extension-accelerate ``` LANGUAGE: pnpm CODE: ``` pnpm add @prisma/extension-accelerate ``` ---------------------------------------- TITLE: Add New Guide to Docusaurus Sidebar DESCRIPTION: This TypeScript code snippet demonstrates how to register a new guide in the `sidebars.ts` configuration file for a Docusaurus project. It adds a new path to the 'Framework Guides' category, ensuring the guide appears in the navigation sidebar and is sorted alphabetically. SOURCE: https://github.com/prisma/docs/blob/main/content/800-guides/999-making-guides.mdx#_snippet_3 LANGUAGE: typescript CODE: ``` { type: "category", label: "Framework Guides", collapsed: false, collapsible: false, items: [ "guides/turborepo", "guides/nextjs", "guides/nuxt", "guides/tanstack-start", "guides/react-router-7", "guides/solid-start", "guides/sveltekit", "guides/__________", ].sort(), } ``` ---------------------------------------- TITLE: Initializing Node.js Project and Installing Prisma CLI (npm) DESCRIPTION: This snippet initializes a new Node.js project, creating a `package.json` file with default settings. It then installs the Prisma CLI as a development dependency, making it available for use in the project for database operations and migrations. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/110-relational-databases-node-planetscale.mdx#_snippet_0 LANGUAGE: bash CODE: ``` npm init -y npm install prisma --save-dev ``` ---------------------------------------- TITLE: Downloading and Extracting Prisma Example (Terminal) DESCRIPTION: This terminal command sequence downloads the latest Prisma Render deployment example from GitHub, extracts its contents, and then changes the current directory into the newly extracted project folder. This prepares the local environment for understanding and deploying the application. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/200-prisma-client/500-deployment/101-traditional/225-deploy-to-render.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` curl https://codeload.github.com/prisma/prisma-examples/tar.gz/latest | tar -xz --strip=2 prisma-examples-latest/deployment-platforms/render cd render ``` ---------------------------------------- TITLE: Example .env file for Database Connection String DESCRIPTION: This snippet provides an example of a `.env` file, demonstrating how to store the `DATABASE_URL` connection string. It's recommended to keep this file in `.gitignore` and manage environment variables securely in the deployment environment, such as Netlify. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/200-prisma-client/500-deployment/201-serverless/500-deploy-to-netlify.mdx#_snippet_2 LANGUAGE: bash CODE: ``` # Connect to DB DATABASE_URL="postgresql://postgres:__PASSWORD__@__HOST__:__PORT__/__DB_NAME__" ``` ---------------------------------------- TITLE: Installing Prisma Client Package (Terminal) DESCRIPTION: This command installs the `@prisma/client` npm package, which is the core library for interacting with your database using Prisma. It is a prerequisite for generating and using the Prisma Client in your project. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/100-start-from-scratch/120-mongodb/200-install-prisma-client-typescript-mongodb.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` npm install @prisma/client ``` ---------------------------------------- TITLE: Examples of Vague Variable Names in TypeScript DESCRIPTION: This TypeScript snippet illustrates examples of poor variable naming conventions, such as `results` (too generic) and `foo` (too vague). Such names hinder code understanding, make debugging more challenging, and should be avoided for clarity. SOURCE: https://github.com/prisma/docs/blob/main/content/600-about/20-style-guide/03-spelling-punctuation-formatting.mdx#_snippet_4 LANGUAGE: ts CODE: ``` const results = (...) // Too generic const foo = (...) // Too vague ``` ---------------------------------------- TITLE: Prisma Info Log Example DESCRIPTION: Shows a typical example of an `info` level log message, often indicating server startup or other informational events. SOURCE: https://github.com/prisma/docs/blob/main/content/200-orm/500-reference/050-prisma-client-reference.mdx#_snippet_6 LANGUAGE: Text CODE: ``` prisma:info Started http server on http://127.0.0.1:58471 ``` ---------------------------------------- TITLE: Navigate into New Project Directory DESCRIPTION: After the `try-prisma` command completes, use this command to change the current working directory to the newly created project folder. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/01-quickstart-prismaPostgres.mdx#_snippet_1 LANGUAGE: terminal CODE: ``` cd hello-prisma ``` ---------------------------------------- TITLE: Invoking Prisma CLI with npx (Terminal) DESCRIPTION: This command demonstrates how to invoke the Prisma CLI using `npx`, a tool that allows running Node.js package executables without globally installing them. It's a common and recommended way to interact with Prisma commands. SOURCE: https://github.com/prisma/docs/blob/main/content/100-getting-started/02-setup-prisma/200-add-to-existing-project/_prisma-init-partial.mdx#_snippet_0 LANGUAGE: terminal CODE: ``` npx prisma ``` ---------------------------------------- TITLE: Generating Prisma Client with Data Proxy Option (Prisma < 5.0.0) DESCRIPTION: This command is used for Prisma versions older than `5.0.0` to generate the Prisma Client with the `--data-proxy` option. This flag enables the client to connect through a data proxy, which was the precursor to the `--accelerate` option for proxy-based connections. SOURCE: https://github.com/prisma/docs/blob/main/content/300-accelerate/200-getting-started.mdx#_snippet_8 LANGUAGE: terminal CODE: ``` npx prisma generate --data-proxy ```