Missing modelSlice methods? #310
-
The 0.29.0 changelog states:
However, there are no Additionally, the current model documentation continues to refer to the old, non-existent methods. Are these methods missing? Is the changelog mistaken? What is the current recommended pattern for inserting, updating, and deleting using the generated models? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The docs definitely need to be updated. The CHANGELOG also has a mistake.... InsertOld wayPreviously you could insert a slice of Setters with user, err := models.Users.Insert(ctx, db, setter) // insert one
users, err := models.Users.InsertMany(ctx, db, setters...) // insert many New wayNow, each setter is an insert mod by itself: user, err := models.Users.Insert(setter).One(ctx, db) // insert one
users, err := models.Users.Insert(setters[0], setters[1]).All(ctx, db) // insert many
// For cases where you already have a slice of setters and you want to pass them all, you can use `bob.ToMods`
users, err := models.Users.Insert(bob.ToMods(setters)).All(ctx, db) // insert many Update and DeleteThis one is more a typo, However, the implementation is quite trivial if you take a look at the generated code func (o UserSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals UserSetter) error {
_, err := Users.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o UserSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
_, err := Users.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
} |
Beta Was this translation helpful? Give feedback.
The docs definitely need to be updated.
There have been quite a few large changes recently, and the docs have not been updated to match.
The CHANGELOG also has a mistake....
Insert
Old way
Previously you could insert a slice of Setters with
table.Insert
andtable.InsertMany
:New way
Now, each setter is an insert mod by itself: