-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(fields): add select & omit docs (#1253)
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -14,5 +14,6 @@ | |
"raw": "", | ||
"transactions": "", | ||
"composite": "", | ||
"fields": "", | ||
"limitations": "" | ||
} |
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,51 @@ | ||
# Field selection and omission | ||
|
||
You can select or omit fields in the query API. This is useful for reducing the amount of data you need to fetch, or | ||
for reducing the amount of data you need to send from the database to the client (up until to the end user) | ||
|
||
The examples use the following prisma schema: | ||
|
||
```prisma | ||
model User { | ||
id String @id @default(cuid()) | ||
name String? | ||
password String? | ||
age Int? | ||
} | ||
``` | ||
|
||
## Notes | ||
|
||
You can only select or omit fields in a query, not both. | ||
|
||
## Select | ||
|
||
Select returns only the fields you specify, and nothing else. | ||
|
||
```go | ||
users, err := client.User.FindMany( | ||
User.Name.Equals("john"), | ||
).Select( | ||
User.Name.Field(), | ||
).Exec(ctx) | ||
if err != nil { | ||
panic(err) | ||
} | ||
``` | ||
|
||
## Omit | ||
|
||
Omit returns all fields except the ones you specify. | ||
|
||
```go | ||
users, err := client.User.FindMany( | ||
User.Name.Equals("a"), | ||
).Omit( | ||
User.ID.Field(), | ||
User.Password.Field(), | ||
User.Age.Field(), | ||
User.Name.Field(), | ||
).Exec(ctx) | ||
if err != nil { | ||
panic(err) | ||
} |