Skip to content

Commit

Permalink
docs: update example on readme to use GetAs function
Browse files Browse the repository at this point in the history
  • Loading branch information
sesaquecruz authored Jan 8, 2024
1 parent 63212ac commit e115694
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,17 @@ UOW.Register("OrderRepository", func(tx *sql.Tx) uow.Repository {
```
err = UOW.Do(ctx, func(ctx context.Context, tx uow.TX) error {
// Get repositories
// ...
// Get product repository
repository, err := tx.Get("ProductRepository")
productRepository, err := uow.GetAs[*ProductRepository](tx, "ProductRepository")
if err != nil {
return err
}
productRepository, ok := repository.(*ProductRepository)
if !ok {
return errors.New("invalid repository type")
}
// Get order repository
repository, err = tx.Get("OrderRepository")
orderRepository, err := uow.GetAs[*OrderRepository](tx, "OrderRepository")
if err != nil {
return err
}
orderRepository, ok := repository.(*OrderRepository)
if !ok {
return errors.New("invalid repository type")
}
// Execute operations
// ...
})
Expand Down

0 comments on commit e115694

Please sign in to comment.