-
Notifications
You must be signed in to change notification settings - Fork 788
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add development workflow for Accelerate
- Loading branch information
1 parent
b490ca3
commit bb957e4
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
content/800-data-platform/100-accelerate/580-local-development.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
title: 'Development workflow' | ||
metaTitle: 'Accelerate: Development environment' | ||
metaDescription: 'Learn about Prisma Accelerate in a development environment.' | ||
tocDepth: 3 | ||
toc: true | ||
--- | ||
|
||
<TopBlock> | ||
|
||
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. | ||
|
||
</TopBlock> | ||
|
||
## Prisma Accelerate with a local database | ||
|
||
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. | ||
|
||
<img src="images/accelerate-in-dev.png" alt="" /> | ||
|
||
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. | ||
|
||
<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`. | ||
|
||
Here is how to use a local PostgreSQL database with Prisma ORM and Prisma Accelerate client extension (without caching and connection pooling): | ||
|
||
1. Paste your local database URL in your .env file | ||
|
||
```.env | ||
DATABASE_URL="postgres://username:[email protected]:5432/localdb" | ||
``` | ||
|
||
2. Generate a Prisma Client | ||
|
||
```bash | ||
npx prisma generate | ||
``` | ||
|
||
> Note: The `--no-engine` cannot be used when working with a local database, as it generates an engineless Prisma Client which requires the use of an Accelerate connection string. | ||
3. Add Prisma Accelerate to your project | ||
|
||
```typescript | ||
import { PrismaClient } from '@prisma/client' | ||
import { withAccelerate } from '@prisma/extension-accelerate' | ||
|
||
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. | ||
## Using Prisma Accelerate in edge functions in a development environment | ||
|
||
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. | ||
|
||
To create this engineless PrismaClient, run the command `prisma generate --no-engine`. Now, you will be able to use `PrismaClient` for the edge. | ||
|
||
```bash | ||
import { PrismaClient } from "@prisma/client/edge"; | ||
``` | ||
You must use the Accelerate connection string to use `PrismaClient` for the edge with Accelerate. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+142 KB
content/800-data-platform/100-accelerate/images/accelerate-in-prod.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.