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

2.16.0 and Refactor: Prisma Client API reference #1014

Merged
merged 90 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
cad6ee7
First pass at API ref
Nov 11, 2020
a26b653
Force prettier to use Markdown parser
Nov 12, 2020
571f2a9
Moved error reference
Nov 13, 2020
f391f3d
Client API
Nov 13, 2020
3dc0890
Filtering reference
Nov 13, 2020
65dc957
API reference
Nov 17, 2020
a32a8fc
Reference docs
Nov 17, 2020
c976cd0
Migrating content
Nov 18, 2020
ba19910
API ref
Nov 18, 2020
1776b63
Shifted pages around
Nov 19, 2020
c857c11
Reworking selection set page
Nov 19, 2020
55adb21
CRUD and select/include
Nov 19, 2020
c2b1e01
API ref + cnceptual
Nov 23, 2020
2c3b65b
Relations / reference
Nov 24, 2020
ec49556
Relations queries
Nov 24, 2020
00418a4
Merge branch 'master' of https://github.com/prisma/prisma2-docs into …
Nov 25, 2020
5585288
ORM update
Nov 25, 2020
db25666
findOne
Nov 25, 2020
d783ec8
Crud examples
Nov 26, 2020
20553dd
Merge branch 'master' of https://github.com/prisma/prisma2-docs into …
Dec 10, 2020
31d3912
CRUD
Dec 10, 2020
f00f0df
API reference
Dec 15, 2020
ab62cd9
Merge branch 'master' of https://github.com/prisma/prisma2-docs into …
Dec 15, 2020
6a0e731
Reference
Dec 17, 2020
57b1e4b
Reference
Dec 18, 2020
30f67ba
Added 'file' to a loooooooot of examples
Dec 18, 2020
46fac84
File annotations for ts
Dec 18, 2020
6cb78ea
Removed file=script.ts
Dec 18, 2020
731b161
Removed code sample files
Dec 21, 2020
37f9c62
Combined filter and sort
Jan 4, 2021
9409a3f
Merge branch 'master' of https://github.com/prisma/prisma2-docs into …
Jan 4, 2021
e68bda8
Merge branch 'master' of https://github.com/prisma/prisma2-docs into …
Jan 18, 2021
2b770c9
API reference
Jan 18, 2021
41bb545
API ref
Jan 18, 2021
d4d5a92
Group by client ref
Jan 18, 2021
5f12afa
Fixing links
Jan 19, 2021
d87423b
Merge branch 'master' into prisma-client-api
Jan 23, 2021
bde10c6
API ref
Jan 25, 2021
dcf62bc
Merge branch 'master' into prisma-client-api
Jan 25, 2021
cf7e115
Select / relation
Jan 26, 2021
0f8c2be
Relations intro
Jan 26, 2021
68d0b4a
Error ref, field selection ,filtering
Jan 26, 2021
5d552ae
Error ref formatting fix
Jan 26, 2021
76f8beb
Apply suggestions from code review
mhwelander Jan 26, 2021
a4f34af
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Jan 26, 2021
909f5ab
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Jan 26, 2021
5baaf46
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Jan 26, 2021
25ab6a6
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Jan 26, 2021
862fb33
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Jan 26, 2021
e9feeb4
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Jan 26, 2021
a219d30
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Jan 26, 2021
9abafa1
Ref fixes
Jan 26, 2021
2324b2b
Merge branch 'prisma-client-api' of https://github.com/prisma/prisma2…
Jan 26, 2021
749363f
Style guide
Jan 26, 2021
23e5642
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Jan 26, 2021
10cbc5d
2.15.0 docs
Jan 27, 2021
ba6718d
Filtering and CRUD
Jan 29, 2021
65b7ca6
SIte title update
Jan 29, 2021
5559751
Template
Jan 29, 2021
c3a64ec
SElect fields
Jan 29, 2021
0e88da2
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Jan 29, 2021
f62b1c2
Fixing broken links
Feb 1, 2021
fe2da48
Changed prettier config
Feb 1, 2021
be3c9ba
findONe
Feb 2, 2021
885fb74
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Feb 2, 2021
a04ecc4
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Feb 2, 2021
25df3d3
General formatting change
Feb 2, 2021
d512d7c
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Feb 2, 2021
c2a2ad3
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Feb 2, 2021
1abcd11
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Feb 2, 2021
1c2ebad
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Feb 2, 2021
c75b9da
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Feb 2, 2021
20327b4
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Feb 2, 2021
1c2947d
Feedback
Feb 2, 2021
0c4752b
Merge branch 'prisma-client-api' of https://github.com/prisma/prisma2…
Feb 2, 2021
6a9a370
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Feb 2, 2021
e247a3f
Update content/400-reference/200-api-reference/050-prisma-client-refe…
mhwelander Feb 2, 2021
9c0bd14
Small fixes
Feb 2, 2021
eb05350
Merge branch 'prisma-client-api' of https://github.com/prisma/prisma2…
Feb 2, 2021
53242bf
Fix broken links
Feb 2, 2021
8e4ad0c
Formatting fixes
Feb 2, 2021
12829f3
createMany
Feb 3, 2021
d26f5d0
Ordering
Feb 3, 2021
f72a7d1
Sort by
Feb 3, 2021
240f637
2.16.0 docs
Feb 3, 2021
49858e6
What's new + broken links
Feb 3, 2021
c38aa75
Update what's new
Feb 3, 2021
96c761d
Merge branch 'master' into prisma-client-api
Feb 3, 2021
402eca2
Link fixes
Feb 3, 2021
0fb6180
Schema update
Feb 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/100-getting-started/01-quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ This should print the following result to your terminal:
]
```

One of the main features of Prisma Client is the ease of working with relations. You can retrieve the `posts` of each user by using the [`include`](../concepts/components/prisma-client/field-selection#include) option. Adjust your code to look as follows:
One of the main features of Prisma Client is the ease of working with relations. You can retrieve the `posts` of each user by using the [`include`](../concepts/components/prisma-client/select-fields#include) option. Adjust your code to look as follows:

<SwitchTech technologies={['typescript']}>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: 'Add to existing project'
# metaDescription: 'Learn how to add Prisma to an existing Node.js or TypeScript project by connecting it to your database and generating Prisma Client for database access.'
langSwitcher: ['typescript', 'node']
dbSwitcher: ['postgres', 'mysql']
duration: '15 min'
techMetaTitles: [
{name: 'node-postgres', value: 'Add to existing project (Node.js & PostgreSQL)'},
{name: 'typescript-postgres', value: 'Add to existing project (TypeScript & PostgreSQL)'},
Expand Down Expand Up @@ -372,7 +373,7 @@ Right now, there's a few minor "issues" with the data model:
- The `Post` and `Profile` relation fields on `User` as well as the `User` relation field on `Profile` are all uppercased. To adhere to Prisma's [naming conventions](../../reference/api-reference/prisma-schema-reference#naming-conventions-1) <span class="api"></span>, both fields should be lowercased to `post`, `profile` and `user`.
- Even after lowercasing, the `post` field on `User` is still slightly misnamed. That's because it actually refers to a [list](../../concepts/components/prisma-schema/data-model#type-modifiers) of posts – a better name therefore would be the plural form: `posts`.

These changes are relevant for the generated Prisma Client API where using lowercased relation fields `author`, `posts`, `profile` and `user` will feel more natural and idiomatic to JavaScript/TypeScript developers. You can therefore [configure your Prisma Client API](../../concepts/components/prisma-client/configuring-the-prisma-client-api).
These changes are relevant for the generated Prisma Client API where using lowercased relation fields `author`, `posts`, `profile` and `user` will feel more natural and idiomatic to JavaScript/TypeScript developers. You can therefore [configure your Prisma Client API](../../concepts/components/prisma-client/generating-the-prisma-client/customizing-the-prisma-client-api).

Because [relation fields](../../concepts/components/prisma-schema/relations#relation-fields) are _virtual_ (i.e. they _do not directly manifest in the database_), you can manually rename them in your Prisma schema without touching the database:

Expand Down Expand Up @@ -451,7 +452,7 @@ const user = await prisma.myUser.create({
})
```

Learn more about this on the [Configuring your Prisma Client API](../../concepts/components/prisma-client/configuring-the-prisma-client-api) page.
Learn more about this on the [Configuring your Prisma Client API](../../concepts/components/prisma-client/generating-the-prisma-client/customizing-the-prisma-client-api) page.

## Install and generate Prisma Client

Expand Down Expand Up @@ -655,7 +656,7 @@ async function main() {

This code creates a new `User` record together with new `Post` and `Profile` records using a [nested write](../../concepts/components/prisma-client/relation-queries#nested-writes) query. The `User` record is connected to the two other ones via the `Post.author` ↔ `User.posts` and `Profile.user` ↔ `User.profile` [relation fields](../../concepts/components/prisma-schema/relations#relation-fields) respectively.

Notice that you're passing the [`include`](../../concepts/components/prisma-client/field-selection#include) option to `findMany` which tells Prisma Client to include the `posts` and `profile` relations on the returned `User` objects.
Notice that you're passing the [`include`](../../concepts/components/prisma-client/select-fields#include) option to `findMany` which tells Prisma Client to include the `posts` and `profile` relations on the returned `User` objects.

<SwitchTech technologies={['typescript', '*']}>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: 'Start from scratch'
# metaDescription: 'Learn how to create a new Node.js or TypeScript project from scratch by connecting Prisma to your database and generating Prisma Client for database access.'
langSwitcher: ['typescript', 'node']
dbSwitcher: ['postgres', 'mysql']
duration: '15 min'
techMetaTitles:
[
{ name: 'node-postgres', value: 'Start from scratch | Node.js & PostgreSQL' },
Expand Down Expand Up @@ -583,7 +584,7 @@ async function main() {

This code creates a new `User` record together with new `Post` and `Profile` records using a [nested write](../../concepts/components/prisma-client/relation-queries#nested-writes) query. The `User` record is connected to the two other ones via the `Post.author` ↔ `User.posts` and `Profile.user` ↔ `User.profile` [relation fields](../../concepts/components/prisma-schema/relations#relation-fields) respectively.

Notice that you're passing the [`include`](../../concepts/components/prisma-client/field-selection#include) option to `findMany` which tells Prisma Client to include the `posts` and `profile` relations on the returned `User` objects.
Notice that you're passing the [`include`](../../concepts/components/prisma-client/select-fields#include) option to `findMany` which tells Prisma Client to include the `posts` and `profile` relations on the returned `User` objects.

Run the code with this command:

Expand Down
2 changes: 1 addition & 1 deletion content/100-getting-started/02-setup-prisma/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
title: 'Set up Prisma'
metaTitle: ''
metaDescription: ''
duration: '15 min'
toc: false
staticLink: true
---

<TopBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ The typical workflow when using **SQL migrations and introspection** looks as fo

1. Manually adjust your database schema using SQL
1. (Re-)introspect your database
1. Optionally (re-)configure your Prisma Client API ([learn more](../../components/prisma-client/configuring-the-prisma-client-api))
1. Optionally (re-)configure your Prisma Client API ([learn more](../../components/prisma-client/generating-the-prisma-client/customizing-the-prisma-client-api))
1. (Re-)generate Prisma Client
1. Use Prisma Client in your application code to access your database

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Prisma uses the provider that is compatible with the the value of the `url` fiel

Prisma resolves SSL certificates relative to the `.\prisma` directory. If your certificate files are located in the root directory, use relative paths for certificates:

```prisma file=schema.prisma
```prisma
datasource db {
provider = "postgresql"
url = "postgresql://johndoe:mypassword@localhost:5432/mydb?schema=public&sslmode=require&sslcert=../server-ca.pem&sslidentity=../client-identity.p12&sslpassword=<REDACTED>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ With this model definition, Prisma automatically maps the `Comment` model to the

> **Note**: You can also [`@map`](../../../reference/api-reference/prisma-schema-reference#map) <span class="api"></span> a column name or enum value, and `@@map` an enum.

`@map` and `@@map` allow you to [tune the shape of your Prisma Client API](../prisma-client/configuring-the-prisma-client-api#using-map-and-map-to-rename-fields-and-models-in-the-prisma-client-api) by decoupling model and field names from table and column names in the underlying database.
`@map` and `@@map` allow you to [tune the shape of your Prisma Client API](../prisma-client/generating-the-prisma-client/customizing-the-prisma-client-api#using-map-and-map-to-rename-fields-and-models-in-the-prisma-client-api) by decoupling model and field names from table and column names in the underlying database.

## Defining fields

Expand Down Expand Up @@ -510,7 +510,7 @@ If you do not specify an index name, introspection generates [a name based on Pr

You can define enums in your data model [if they're supported by the data source you use](../../../reference/database-reference/database-features#misc).

Enums are considered [scalar](#field-types) types in the Prisma data model. They're therefore [by default](../prisma-client/field-selection#the-default-selection-set) included as return values in [Prisma Client queries](../prisma-client/crud).
Enums are considered [scalar](#field-types) types in the Prisma data model. They're therefore [by default](../prisma-client/select-fields#the-default-selection-set) included as return values in [Prisma Client queries](../prisma-client/crud).

Enums are defined via the [`enum`](../../../reference/api-reference/prisma-schema-reference#enum) <span class="api"></span> block. For example, a `User` has a `Role`:

Expand Down Expand Up @@ -541,7 +541,7 @@ model Post {
}
```

[`cuid()`](../../../reference/api-reference/prisma-schema-reference#cuid) <span class="api"></span> and [`uuid()`](../../../reference/api-reference/prisma-schema-reference#uuid) <span class="api"></span> are implemented by Prisma and therefore are not "visible" in the underlying database schema. You can still use them when using [introspection](../introspection) by [manually changing your Prisma schema](../prisma-client/configuring-the-prisma-client-api) and [generating Prisma Client](../prisma-client/generating-prisma-client), in that case the values will be generated by Prisma's [query engine](../prisma-client/query-engine)
[`cuid()`](../../../reference/api-reference/prisma-schema-reference#cuid) <span class="api"></span> and [`uuid()`](../../../reference/api-reference/prisma-schema-reference#uuid) <span class="api"></span> are implemented by Prisma and therefore are not "visible" in the underlying database schema. You can still use them when using [introspection](../introspection) by [manually changing your Prisma schema](../prisma-client/generating-the-prisma-client/customizing-the-prisma-client-api) and [generating Prisma Client](../prisma-client/generating-prisma-client), in that case the values will be generated by Prisma's [query engine](../prisma-client/query-engine)

`autoincrement()`, `now` and `dbgenerated()` are always "implemented" on the database-level, meaning they manifest in the database schema and can be recognized through introspection.

Expand Down Expand Up @@ -581,7 +581,7 @@ const allUsers = await prisma.user.findMany()

Prisma Client not only provides a query API for models, it also generates type definitions that reflect your model structures. These are part of the generated [`@prisma/client`](../prisma-client/generating-prisma-client#the-prismaclient-npm-package) node module in a file called `index.d.ts`.

When using TypeScript, these type definitions ensure that all your database queries are entirely type safe and validated at compile-time (even partial queries using [`select`](../prisma-client/field-selection#select) or [`include`](../prisma-client/field-selection#include)).
When using TypeScript, these type definitions ensure that all your database queries are entirely type safe and validated at compile-time (even partial queries using [`select`](../prisma-client/select-fields#select) or [`include`](../prisma-client/select-fields#include)).

Even when using plain JavaScript, the type definitions are still included in the `@prisma/client` node module, enabling features like [IntelliSense](https://code.visualstudio.com/docs/editor/intellisense)/autocompletion in your editor.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metaDescription: 'A relation is a connection between two models in the Prisma sc

A relation is a _connection_ between two models in the Prisma schema. For example, there is a one-to-many relation between `User` and `Post` because one user can have many blog posts. The following Prisma schema defines a one-to-many relation between the `User` and `Post` models. The fields involved in defining the relation are highlighted:

```prisma line-number
```prisma line-number file=schema.prisma
model User {
id Int @id @default(autoincrement())
| posts Post[]
Expand Down Expand Up @@ -903,7 +903,7 @@ To create a one-to-one self-relation:

Either side of the relation can be backed by a foreign key. In the following example, `successor` is backed by `successorId`:

```prisma line-number
```prisma line-number file=schema.prisma
model User {
id Int @default(autoincrement()) @id
name String?
Expand All @@ -915,7 +915,7 @@ model User {

In the following example, `predecessor` is backed by `predecessorId`:

```prisma line-number
```prisma line-number file=schema.prisma
model User {
id Int @default(autoincrement()) @id
name String?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: 'Configuring the Prisma Client API'
metaTitle: 'Configuring the Prisma Client API (Reference)'
title: 'Customizing the client'
metaTitle: 'Customizing the client (Concepts)'
metaDescription: 'Learn how you can decouple the naming of Prisma models from database tables to improve the ergonomics of the generated Prisma Client API.'
---

Expand Down

This file was deleted.

Loading