mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
ent/doc: add example for select api
Reviewed By: dlvhdr Differential Revision: D17183384 fbshipit-source-id: 39072346582a70b74f9eb78137a9f9357117ca84
This commit is contained in:
committed by
Facebook Github Bot
parent
95d878d3c6
commit
b26334c93c
@@ -199,6 +199,32 @@ users, err := a8m.
|
||||
QueryPets().
|
||||
All(ctx)
|
||||
```
|
||||
|
||||
Get all pet names.
|
||||
|
||||
```go
|
||||
names, err := client.Pet.
|
||||
Query().
|
||||
Select(pet.FieldName).
|
||||
Strings(ctx)
|
||||
```
|
||||
|
||||
Get all pet names and ages.
|
||||
|
||||
```go
|
||||
var v []struct {
|
||||
Age int `json:"age"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
err := client.Pet.
|
||||
Query().
|
||||
Select(pet.FieldAge, pet.FieldName).
|
||||
Scan(ctx, &v)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
```
|
||||
|
||||
More advance traversals can be found in the [next section](traversals.md).
|
||||
|
||||
## Delete One
|
||||
|
||||
Reference in New Issue
Block a user