-
Notifications
You must be signed in to change notification settings - Fork 743
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
Client constructor #480
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
447b005
Added illustrations
50e83b1
Merge branch 'master' of https://github.com/prisma/prisma2-docs
976c04a
Merge branch 'master' of https://github.com/prisma/prisma2-docs
0c837c5
Client constructor page
ffd6b85
Merge branch 'master' of https://github.com/prisma/prisma2-docs into …
b7bf79a
Merge branch 'master' of https://github.com/prisma/prisma2-docs into …
46aff4e
Constructor docs
b5f3fb5
Fixed index
00d6b04
Added # to page
ee2a7d3
Merge branch 'master' of https://github.com/prisma/prisma2-docs into …
553b4a2
Update content/03-reference/01-tools-and-interfaces/02-prisma-client/…
mhwelander ad65ea7
Joël fixes
17eec52
Merge branch 'client-constructor' of https://github.com/prisma/prisma…
1309e18
Update content/03-reference/01-tools-and-interfaces/02-prisma-client/…
Jolg42 30b9a55
Update 02-constructor.mdx
Jolg42 e806297
Update content/03-reference/01-tools-and-interfaces/02-prisma-client/…
mhwelander File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
content/03-reference/01-tools-and-interfaces/02-prisma-client/02-constructor.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that? Do we not define which one it should be applied to by using
my_database
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @timsuchanek
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a enabled property in the schema before that got removed (never saw it, just the remains)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the connection to this comment? Should it not use the datasource with the name you supply above,
my_database
in this example?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually touching on undefined behavior, I think the Note is correct, but we need to fix that.
Even though you provide a specific datasource as a constructor arg, it could even be, that in our current implementation, it might not be used, if it's not the first datasource in the schema.
We don't have tests for that and didn't define this behavior clearly yet, but should definitely do that asap.