Skip to content

Commit

Permalink
Give direction on using Optimize and Accelerate together (#6311)
Browse files Browse the repository at this point in the history
  • Loading branch information
jharrell authored Oct 4, 2024
1 parent 98ce03a commit 75b4e12
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
24 changes: 15 additions & 9 deletions content/300-accelerate/200-getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,9 @@ When using Prisma Accelerate in a Serverless or an Edge application, we recommen
npx prisma generate --no-engine
```

<Admonition type="info">

The `--no-engine` flag prevents a Query Engine file from being included in the generated Prisma Client, this ensures the bundle size of your application remains small.

</Admonition>

<Admonition type="warning">
:::warning

If your Prisma version is below `5.2.0`, generate Prisma Client with the `--accelerate` option:

Expand All @@ -118,7 +114,11 @@ npx prisma generate --accelerate

If your Prisma version is below `5.0.0`, generate Prisma Client with the `--data-proxy` option:

</Admonition>
```terminal
npx prisma generate --data-proxy
```

:::

### 2.4. Extend your Prisma Client instance with the Accelerate extension

Expand All @@ -142,16 +142,22 @@ const prisma = new PrismaClient().$extends(withAccelerate())

If VS Code does not recognize the `$extends` method, refer to [this section](/accelerate/faq#vs-code-does-not-recognize-the-extends-method) on how to resolve the issue.

<Admonition type="info">
#### Using the Accelerate extension with other extensions or middleware

Since [extensions are applied one after another](/orm/prisma-client/client-extensions#conflicts-in-combined-extensions), make sure you apply them in the correct order. Extensions cannot share behavior and the last extension applied takes precedence.

If you are using [Prisma Optimize](/optimize) in your application, make sure you apply it _before_ the Accelerate extension. For example:

```ts
const prisma = new PrismaClient().$extends(withOptimize()).$extends(withAccelerate())
```

If you are using [Prisma Middleware](/orm/prisma-client/client-extensions/middleware) in your application, make sure they are added before any Prisma Client extensions (like Accelerate). For example:

```ts
const prisma = new PrismaClient().$use(middleware).$extends(withAccelerate())
```

</Admonition>

### 2.5. Use Accelerate in your database queries

The `withAccelerate` extension primarily does two things:
Expand Down
16 changes: 16 additions & 0 deletions content/700-optimize/200-getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ const prisma = new PrismaClient().$extends(
);
```

#### Using the Optimize extension with other extensions or middleware

Since [extensions are applied one after another](/orm/prisma-client/client-extensions#conflicts-in-combined-extensions), make sure you apply them in the correct order. Extensions cannot share behavior and the last extension applied takes precedence.

If you are using [Prisma Accelerate](/accelerate) in your application, make sure you apply it _after_ the Optimize extension. For example:

```ts
const prisma = new PrismaClient().$extends(withOptimize()).$extends(withAccelerate())
```

If you are using [Prisma Middleware](/orm/prisma-client/client-extensions/middleware) in your application, make sure they are added before any Prisma Client extensions (like Optimize). For example:

```ts
const prisma = new PrismaClient().$use(middleware).$extends(withOptimize())
```

### 2.5. Use Prisma Optimize to generate insights

Follow these steps to start generating query insights with Prisma Optimize:
Expand Down

0 comments on commit 75b4e12

Please sign in to comment.