Skip to content

Commit

Permalink
Client constructor (#480)
Browse files Browse the repository at this point in the history
* Added illustrations
Fixed some typos

* Client constructor page

* Constructor docs

* Fixed index

* Added # to page

* Update content/03-reference/01-tools-and-interfaces/02-prisma-client/02-constructor.mdx

Co-authored-by: Tim Suchanek <Tim.Suchanek@gmail.com>

* Joël fixes

* Update content/03-reference/01-tools-and-interfaces/02-prisma-client/02-constructor.mdx

* Update 02-constructor.mdx

* Update content/03-reference/01-tools-and-interfaces/02-prisma-client/02-constructor.mdx

Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>

Co-authored-by: Tim Suchanek <Tim.Suchanek@gmail.com>
Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>
  • Loading branch information
4 people authored and mhwelander committed Jul 2, 2020
1 parent 4590a58 commit ec4c1a4
Showing 1 changed file with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
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 datasource in the `schema.prisma` 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: {
| url: 'file:./dev_qa.db'
| }
},
})
```

> **Note**: If you define multiple datasources in `schema.prisma`, 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 'colorless'
})
```

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

0 comments on commit ec4c1a4

Please sign in to comment.