Skip to content

Commit

Permalink
enhance: reduce redundancy in text
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur-arch committed Nov 29, 2023
1 parent 9f1a4e5 commit 0442259
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions content/800-data-platform/100-accelerate/580-local-development.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ toc: true

Prisma Accelerate is designed to efficiently scale database connections in a production environment while providing a global cache. To leverage the benefits of connection pooling and a global cache, it is essential to utilize a publicly accessible database.

In development environments, using a publicly available database may not be possible, and you may want to use a local database. Here, we will explain how to use Prisma Accelerate client extension in a development environment with a local database.
In development environments, you may want to use a local database to minimize expenses.

</TopBlock>

## Prisma Accelerate with a local database
Furthermore, you may consider extending `PrismaClient` 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.

To benefit from Accelerate's connection pool and global cache features, you must have a publicly accessible database, enabling the creation of a Prisma Accelerate URL. It's important to note that Accelerate's features won't function with a local database.
Here, we will explain how to use Prisma Accelerate client extension in a development environment with a local database.

<img src="images/accelerate-in-dev.png" alt="" />
</TopBlock>

However, using a local database URL, you can add the Accelerate client extension to your Prisma Client. This will allow you to use a local database in your development environment. Keep in mind that, in this scenario, caching and connection pooling won't be available.
## Using Prisma Accelerate client extension in development and production

<img src="images/accelerate-in-prod.png" alt="" />
<br />
<img src="images/accelerate-in-dev.png" alt="" />

In a production environment, when a generated Accelerate connection string is used, you will be able to use connection pooling and caching by adding the Accelerate client extension to the `PrismaClient`.
Accelerate doesn’t work with a local database. However, using a local database URL, you can add the Accelerate client extension to your Prisma Client. This will allow you to use a local database in your development environment. Keep in mind that, in this scenario, caching and connection pooling won't be available.

Here is how to use a local PostgreSQL database with Prisma ORM and Prisma Accelerate client extension (without caching and connection pooling):

Expand All @@ -51,16 +50,18 @@ Here is how to use a local PostgreSQL database with Prisma ORM and Prisma Accele
const prisma = new PrismaClient().$extends(withAccelerate())
```

> `PrismaClient` infers that a local database is being used from the database connection string and disables the connection pooling and caching functionalities of Prisma Accelerate.
> `PrismaClient` with the Accelerate client extension uses the local database connection. Accelerate won’t work as a local database is being used.
## Using Prisma Accelerate in edge functions in a development environment
<img src="images/accelerate-in-prod.png" alt="" />

In a production environment, when a generated Accelerate connection string is used, you will be able to use connection pooling and caching by adding the Accelerate client extension to the `PrismaClient`.

When working with Prisma Accelerate in a dev environment for [Next.js edge functions](https://vercel.com/docs/functions/edge-functions), you must use a `PrismaClient` without an engine.
## Locally using Prisma Accelerate in edge functions

To create this engineless PrismaClient, run the command `prisma generate --no-engine`. Now, you will be able to use `PrismaClient` for the edge.
When working with Prisma Accelerate in a dev environment for [Next.js edge functions](https://vercel.com/docs/functions/edge-functions), you must use `PrismaClient` that can be used in edge functions.

```bash
import { PrismaClient } from "@prisma/client/edge";
```
You must use the Accelerate connection string to use `PrismaClient` for the edge with Accelerate.
The `PrismaClient` in Next.js edge functions does not support a direct database connection, hence you have to use the Accelerate connection string.

0 comments on commit 0442259

Please sign in to comment.