diff --git a/content/800-data-platform/100-accelerate/580-local-development.mdx b/content/800-data-platform/100-accelerate/580-local-development.mdx new file mode 100644 index 0000000000..d81c24292b --- /dev/null +++ b/content/800-data-platform/100-accelerate/580-local-development.mdx @@ -0,0 +1,65 @@ +--- +title: 'Local development' +metaTitle: 'Accelerate: Local development' +metaDescription: 'Learn how to use Prisma Accelerate in a development environment.' +tocDepth: 3 +toc: true +--- + + + +Prisma Accelerate is designed to scale database connections efficiently in production environments. Prisma Accelerate also provides a global cache to reduce the load on your database and reduce query response time. To leverage Prisma Accelerate, it is essential to utilize a publicly accessible database. + +In development environments, you may want to use a local database to minimize expenses. Furthermore, you may consider extending Prisma Client with the Accelerate client extension once so that you can use a local database in development and a hosted database with Accelerate’s connection pooling and caching enabled. This eliminates the need for conditional logic to switch clients between development and production. + +This guide will explain how to use Prisma Accelerate client extension in a development environment with a local database. + + + +## Using Prisma Accelerate client extension in development and production + +
+ + +Accelerate does not work with a local database. However, in a development environment, you can still use Prisma Client with the Accelerate client extension. This setup will not provide Accelerate's connection pooling and caching features. + +The following steps outline how to use Prisma ORM and Prisma Accelerate with a local PostgreSQL database. + +1. Update the `DATABASE_URL` environment variable with your local database's connection string: + + ```.env + DATABASE_URL="postgres://username:password@127.0.0.1:5432/localdb" + ``` + +2. Generate a Prisma Client: + + ```bash + npx prisma generate + ``` + + > Note: The `--no-engine` flag should only be used in preview and production environments. The command generates Prisma Client artifacts without a [Query Engine](/concepts/components/prisma-engines) file, which requires an Accelerate connection string. + +3. Set up Prisma Client with the Accelerate client extension: + + ```typescript + import { PrismaClient } from '@prisma/client' + import { withAccelerate } from '@prisma/extension-accelerate' + + const prisma = new PrismaClient().$extends(withAccelerate()) + ``` + + > The extended instance of Prisma Client will use the local database. Hence, Prisma Accelerate will not be used in your development environment to respond to your Prisma Client queries. + + + +If an Accelerate connection string is used as the `DATABASE_URL` environment variable, Prisma Client will route your queries through Accelerate. + +## Using Prisma Accelerate locally in an edge function + +When using an edge function, e.g., [Vercel's edge functions](https://vercel.com/docs/functions/edge-functions), for your development environment, update your Prisma Client import as follows: + +```typescript +import { PrismaClient } from "@prisma/client/edge"; +``` + +Generally, edge function environments lack native support for existing APIs enabling TCP-based database connections. Prisma Accelerate provides a connection string that allows querying your database over HTTP, a protocol supported in all edge runtimes. diff --git a/content/800-data-platform/100-accelerate/images/accelerate-in-dev.png b/content/800-data-platform/100-accelerate/images/accelerate-in-dev.png new file mode 100644 index 0000000000..970c06f65d Binary files /dev/null and b/content/800-data-platform/100-accelerate/images/accelerate-in-dev.png differ diff --git a/content/800-data-platform/100-accelerate/images/accelerate-in-prod.png b/content/800-data-platform/100-accelerate/images/accelerate-in-prod.png new file mode 100644 index 0000000000..1e284462f3 Binary files /dev/null and b/content/800-data-platform/100-accelerate/images/accelerate-in-prod.png differ