Skip to content

Commit

Permalink
add note about env vars when using driver adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolasburk committed Mar 12, 2024
1 parent b97cbfb commit 1bcd01b
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tocDepth: 4

## Default built-in drivers

One of Prisma Client's components is the [Query Engine](/orm/more/under-the-hood/engines) . The Query Engine is responsible for transforming Prisma Client queries to SQL statements. The Query Engine connects to your database using the included drivers that don't require additional setup. The built-in drivers use TCP connections to connect to the database.
One of Prisma Client's components is the [Query Engine](/orm/more/under-the-hood/engines). The Query Engine is responsible for transforming Prisma Client queries to SQL statements. The Query Engine connects to your database via TCP using built-in drivers that don't require additional setup.

![Query flow from the user application to the database with Prisma Client](./images/drivers/qe-query-execution-flow.png)

Expand All @@ -19,7 +19,7 @@ Prisma Client will use the Query Engine to transform the Prisma Client query to

![Query flow from the user application to the database using Prisma Client and driver adapters](./images/drivers/qe-query-engine-adapter.png)

There are 2 different types of driver adapters:
There are two different types of driver adapters:

- [Database driver adapters](#database-driver-adapters)
- [Serverless driver adapters](#serverless-driver-adapters)
Expand All @@ -40,13 +40,13 @@ Prisma ORM maintains the following serverless driver adapters:
- [Neon](/orm/overview/databases/neon#how-to-use-neons-serverless-driver-with-prisma-orm-preview)
- [PlanetScale](/orm/overview/databases/planetscale#how-to-use-the-planetscale-serverless-driver-with-prisma-orm-preview)

## Community maintained database driver adapters
### Community-maintained database driver adapters

You can also build your own driver adapter for the database you're using. The following is a list of community maintained driver adapters:

- [TiDB](https://github.com/tidbcloud/prisma-adapter)

### How to use driver adapters
## How to use driver adapters

To use this feature:

Expand All @@ -71,6 +71,26 @@ To use this feature:
- [PlanetScale](/orm/overview/databases/planetscale#how-to-use-the-planetscale-serverless-driver-with-prisma-orm-preview)
- [Turso](/orm/overview/databases/turso#how-to-connect-and-query-a-turso-database)

## Notes about using driver adapters

### Driver adapters don't read the connection string from the Prisma schema

When using Prisma ORM's built-in drivers, the connection string is read from the `url` field of the `datasource` block in your Prisma schema.

On the other hand, when using a driver adapter, the connection string needs to be provided in your _application code_ when the driver adapter is set up initially. Here is how this is done for the `pg` driver and the `@prisma/adapter-pg` adapter:

```ts highlight=5,normal
import { PrismaClient } from '@prisma/client'
import { PrismaPg } from '@prisma/adapter-pg'
import { Pool } from 'pg'

const pool = new Pool({ connectionString: env.DATABASE_URL })
const adapter = new PrismaPg(pool)
const prisma = new PrismaClient({ adapter })
```

See the docs for the driver adapter you're using for concrete setup instructions.

### Driver adapters and custom output paths

Since Prisma 5.9.0, when using the driver adapters Preview feature along with a [custom output path for Prisma Client](/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path), you cannot reference Prisma Client using a relative path.
Expand Down

0 comments on commit 1bcd01b

Please sign in to comment.