mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
doc: add an example for create-bulk api (#650)
This commit is contained in:
@@ -114,16 +114,29 @@ a8m, err := client.User. // UserClient.
|
|||||||
Save(ctx) // Create and return.
|
Save(ctx) // Create and return.
|
||||||
```
|
```
|
||||||
|
|
||||||
**SaveX** a user; Unlike **Save**, **SaveX** panics if an error occurs.
|
**SaveX** a pet; Unlike **Save**, **SaveX** panics if an error occurs.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
pedro := client.Pet. // PetClient.
|
pedro := client.Pet. // PetClient.
|
||||||
Create(). // User create builder.
|
Create(). // Pet create builder.
|
||||||
SetName("pedro"). // Set field value.
|
SetName("pedro"). // Set field value.
|
||||||
SetOwner(a8m). // Set owner (unique edge).
|
SetOwner(a8m). // Set owner (unique edge).
|
||||||
SaveX(ctx) // Create and return.
|
SaveX(ctx) // Create and return.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Create Many
|
||||||
|
|
||||||
|
**Save** a bulk of pets.
|
||||||
|
|
||||||
|
```go
|
||||||
|
names := []string{"pedro", "xabi", "layla"}
|
||||||
|
bulk := make([]*ent.PetCreate, len(names))
|
||||||
|
for i, name := range names {
|
||||||
|
bulk[i] = client.Pet.Create().SetName(name).SetOwner(a8m)
|
||||||
|
}
|
||||||
|
pets, err := client.Pet.CreateBulk(bulk...).Save(ctx)
|
||||||
|
```
|
||||||
|
|
||||||
## Update One
|
## Update One
|
||||||
|
|
||||||
Update an entity that was returned from the database.
|
Update an entity that was returned from the database.
|
||||||
|
|||||||
Reference in New Issue
Block a user