diff --git a/content/200-orm/800-more/600-help-and-troubleshooting/100-help-articles/900-prisma-nuxt-module.mdx b/content/200-orm/800-more/600-help-and-troubleshooting/100-help-articles/900-prisma-nuxt-module.mdx index 65a5f0fe42..c0a3314fa7 100644 --- a/content/200-orm/800-more/600-help-and-troubleshooting/100-help-articles/900-prisma-nuxt-module.mdx +++ b/content/200-orm/800-more/600-help-and-troubleshooting/100-help-articles/900-prisma-nuxt-module.mdx @@ -6,13 +6,13 @@ metaDescription: 'Learn how to easily add Prisma ORM to your Nuxt apps, use its --- -The Nuxt Prisma module simplifies the integration of Prisma ORM into your Nuxt applications. This module provides several features to streamline the setup and usage of Prisma, making it easier to manage your database interactions. +The Nuxt Prisma module simplifies the integration of Prisma ORM into your Nuxt applications. [Prisma ORM](/orm/overview/introduction/what-is-prisma) is a database library that lets you model your database schema, provides auto-generated migrations and lets you query the database in an intuitive and type-safe way. This module provides several features to streamline the setup and usage of Prisma, making it easier to manage your database interactions. -### Features +## Features - **Project initialization**: Automatically sets up a Prisma ORM project with a SQLite database within your Nuxt project. - **Composable**: Provides an auto-imported `usePrismaClient()` composable for use in your Vue files. -- **API Route Integration**: Automatically imports an instance of `prisma` for use in your API routes. +- **API route integration**: Automatically imports an instance of `PrismaClient` for use in your API routes. - **Prisma Studio access**: Enables access to Prisma Studio through Nuxt Devtools for database management. ## Getting Started @@ -43,12 +43,12 @@ The Nuxt Prisma module simplifies the integration of Prisma ORM into your Nuxt a Starting the development server will: - - Automatically install the [Prisma CLI](/orm/reference/prisma-cli-reference) - - Initialize a Prisma project with SQLite - - Create an `User` and `Post` example model in the Prisma Schema - - Prompt you to run a migration to create database tables with [Prisma Migrate](/orm/prisma-migrate/understanding-prisma-migrate/overview) - - Install and generate a [Prisma Client](/orm/reference/prisma-client-reference) - - Prompt you to start the [Prisma Studio](/orm/tools/prisma-studio) + 1. Automatically install the [Prisma CLI](/orm/reference/prisma-cli-reference) + 2. Initialize a Prisma project with SQLite + 3. Create an `User` and `Post` example model in the Prisma Schema + 4. Prompt you to run a migration to create database tables with [Prisma Migrate](/orm/prisma-migrate/understanding-prisma-migrate/overview) + 5. Install and generate a [Prisma Client](/orm/reference/prisma-client-reference) + 6. Prompt you to start the [Prisma Studio](/orm/tools/prisma-studio) 5. You can now use Prisma ORM in your project. If you accepted the prompt to add Prisma Studio, you can access Prisma Studio through the Nuxt Devtools. See the [usage section](#usage) to learn how to use Prisma Client in your app. @@ -84,7 +84,7 @@ export default defineEventHandler(async (event) => { ### Option B: `lib/prisma.ts` After running through the initial setup prompts, this module creates the `lib/prisma.ts` file which contains a global instance of Prisma Client. -```typescript +```typescript file=lib/prisma.ts import { PrismaClient } from '@prisma/client' const prismaClientSingleton = () => { @@ -103,7 +103,7 @@ if (process.env.NODE_ENV !== 'production') globalThis.prismaGlobal = prisma ``` You can customize Prisma Client's capabilities by using client extensions in your `lib/prisma.ts` file. Here is an example using the [Pulse client extension](https://www.npmjs.com/package/@prisma/extension-pulse): -```typescript +```typescript file=lib/prisma.ts import { PrismaClient } from '@prisma/client' import { withPulse } from '@prisma/extension-pulse' @@ -149,4 +149,30 @@ If you're using [Nuxt server components](https://nuxt.com/docs/guide/directory-s -``` \ No newline at end of file +``` + +## Configuration + +You can configure the `@prisma/nuxt` module by using the `prisma` key in `nuxt.config.ts`: + +```ts file=nuxt.config.ts +export default defineNuxtConfig({ + // ... + prisma: { + // Options + } +}) +``` +
+ + The `prisma` key is available in `nuxt.config.ts` after successfully setting up the module by running `npm run dev` + + +| Option | Type | Default | Description | +|---------------------|-----------|---------|-------------| +| **installCLI** | `boolean` | true | Whether to install the [Prisma CLI](/orm/tools/prisma-cli). | +| **installClient** | `boolean` | true | Whether to install the [Prisma Client](/orm/prisma-client) library in the project. | +| **generateClient** | `boolean` | true | Whether to [generate](/orm/prisma-client/setup-and-configuration/generating-prisma-client) the `PrismaClient` instance. Executes `npx prisma generate` on every run to update the client based on the schema changes. | +| **formatSchema** | `boolean` | true | Whether to [format](/orm/reference/prisma-cli-reference#format) the [Prisma Schema](/orm/prisma-schema) file. | +| **installStudio** | `boolean` | true | Whether to install and start [Prisma Studio](https://www.prisma.io/studio) in the Nuxt Devtools. | +| **autoSetupPrisma** | `boolean` | false | Whether to skip all prompts during setup. This option is useful for automating Prisma setup in scripts or CI/CD pipelines. | \ No newline at end of file