Skip to content

Commit

Permalink
fix: remove redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur-arch committed Oct 23, 2023
1 parent f06f1a4 commit 28159ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ git commit -m "initial commit"
git push -u origin main
```

You're ready to import your project into the Prisma Data Platform.
You're ready to create a project in [Prisma Data Platform](https://console.prisma.io).

## 4. Enable Accelerate in Prisma Data Platform

Expand All @@ -151,9 +151,9 @@ To get started, sign up for a free [Prisma Data Platform account](https://consol
1. Add the Prisma Accelerate connection string to your local environment `.env` file and the `DIRECT_URL` environment variable to perform migrations and intropspections.

```diff file=.env
-DATABASE_URL="postgres://..."
+DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=__API_KEY__"
+DIRECT_URL="postgres://..."
-DATABASE_URL="postgres://..."
```

Add [`directUrl`](/reference/api-reference/prisma-schema-reference#fields) property in `datasource` block in the `schema.prisma` file.
Expand All @@ -162,7 +162,7 @@ To get started, sign up for a free [Prisma Data Platform account](https://consol
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
+directUrl = env("DIRECT_URL")
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,31 @@ Setup an Accelerate connection string and proceed to the next step.

With the Accelerate connection string copied, you can replace the direct PostgreSQL connection string that you used to create the database schema in your `.env` file.

Prisma Client for Prisma Accelerate does not read .env files by default, so you must also install dotenv-cli locally.

### Steps

1. Install the Prisma Accelerate client extension
1. Install the `dotenv-cli`.

```
npm install dotenv-cli
```

2. Install the Prisma Accelerate client extension

```bash
npm install @prisma/extension-accelerate
```

2. Add the Accelerate connection string to the `.env` file. Also, comment out the direct connection string.
3. Add the Accelerate connection string to the `.env` file. Also, comment out the direct connection string.

```bash file=.env
DATABASE_URL="DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=__API_KEY__""
# Previous database connection
# DATABASE_URL="postgres://..."
```

3. Add the Prisma Accelerate extension to your Prisma Client
4. Add the Prisma Accelerate extension to your Prisma Client

```typescript
import { PrismaClient } from './generated/client/deno/edge.ts'
Expand Down Expand Up @@ -234,14 +242,14 @@ You can now start your application locally and test the creation of log entries.

3. Reload the page a few times.<br /><br />Every time you reload, the script generates a new log entry and the id of the current log entry increments.

To check whether Accelerate is working, add the `withAccelerateInfo` at the end of your query. This returns an [`info`](/data-platform/accelerate/api-reference#return-type) object which provides additional information on the result of your query.
To get more useful information on queries, add the `withAccelerateInfo` at the end of your query. This returns an [`info`](/data-platform/accelerate/api-reference#return-type) object which provides additional information on the result of your query.

```ts
import { serve } from 'https://deno.land/[email protected]/http/server.ts'
import { PrismaClient } from './generated/client/deno/edge.ts'
+import { withAccelerate } from '@prisma/extension-accelerate'
import { withAccelerate } from '@prisma/extension-accelerate'

+const prisma = new PrismaClient().$extends(withAccelerate())
const prisma = new PrismaClient().$extends(withAccelerate())

async function handler(request: Request) {
const { data, info} = await prisma.log.create({
Expand Down

0 comments on commit 28159ec

Please sign in to comment.