Skip to content

Commit

Permalink
docs(fields): add select & omit docs (#1253)
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen committed Apr 28, 2024
1 parent 6ae3f37 commit e8eef2f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/pages/docs/walkthrough/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"raw": "",
"transactions": "",
"composite": "",
"fields": "",
"limitations": ""
}
51 changes: 51 additions & 0 deletions docs/pages/docs/walkthrough/fields.md
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)
}

0 comments on commit e8eef2f

Please sign in to comment.