Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client constructor #480

Merged
merged 16 commits into from
Jun 30, 2020
Merged
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
title: 'Constructor'
metaTitle: 'Prisma Client Constructor (Reference)'
metaDescription: 'This page describes the Prisma Client constructor parameters.'
---

## Overview

This page describes the Prisma Client constructor parameters.

## `datasources`

Use the `datasources` constructor parameter to programatically override the URL of a datasource - for example, as part of an integration test. To override a datasource:

1. Define a datasources in the `prisma.schema` file. In the following example, there is a single datasource named `my_database`:

```prisma
datasource my_database {
provider = "sqlite"
url = env("DATABASE_URL")
}
```

The `DATABASE_URL` environment variable defines the following value:

```
DATABASE_URL="file:./dev.db"
```

> **Note**: You must re-generate the Prisma Client each time you add or rename a datasource. Datasource names are included in the generated client.

2. Instantiate a client and override the connection string of the `my_database` datasource:

```ts
import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient({
datasources: {
| my_database: 'file:./dev_qa.db',
},
})
janpio marked this conversation as resolved.
Show resolved Hide resolved
```

> **Note**: If you define multiple datasources in `prisma.schema`, Prisma defaults to the first entry.

See [Datasources](../prisma-schema/data-sources) for more information.

## `log`

Use the `log` constructor parameter to determine the type and level of logging. The following configuration raises an event each time the Prisma Client queries the database:

```ts
const prisma = new PrismaClient({
log: [{ emit: 'event', level: 'query' }],
})
```

See [Logging](logging) for more information.

## `errorFormat`

Use the `errorFormat` constructor parameter to determine the level and formatting of errors returned by Prisma. The following configuration outputs raw error messages without formatting or extended information about the error:

```ts
const prisma = new PrismaClient({
errorFormat: 'minimal', // Defaults to 'pretty'
mhwelander marked this conversation as resolved.
Show resolved Hide resolved
})
```

See [Error formatting](error-formatting) for more information.