func Example(ctx context.Context, repo rel.Repository) error {
	var book Book

	// Quickly find a book with id 1 using short alias.
	if err := repo.Find(ctx, &book, where.Eq("id", 1)); err != nil {
		return err
	}

	// Or use chainable query builder.
	query := rel.Select().Where(where.Eq("id", 1)).Limit(1)
	if err := repo.Find(ctx, &book, query); err != nil {
		return err
	}

	// Convenient method to preload Book's Author.
	if err := repo.Preload(ctx, &book, "author"); err != nil {
		return err
	}

	// Performs updates inside a transaction.
	return repo.Transaction(ctx, func(ctx context.Context) error {
		// basic update using struct.
		book.Title = "REL for dummies"
		repo.MustUpdate(ctx, &book)

		// update only specific fields.
		repo.MustUpdate(ctx, &book, rel.Set("discount", false))

		// it even supports atomic inc/dec mutation.
		return repo.Update(ctx, &book, rel.Dec("stock"))
	})
}
// Example is an actual service function that run a complex business package.
// beware: it's actually doing nonsense here.
Example is an actual service function that run a complex business package.
beware: it's actually doing nonsense here.
// Example is an actual service function that run a complex business package . // beware : it ' s actually doing nonsense here .
func Example(ctx context.Context, repo rel.Repository) error {
	var book Book
	if err := repo.Find(ctx, &book, where.Eq("id", 1)); err != nil {
		return err
	}
	query := rel.Select().Where(where.Eq("id", 1)).Limit(1)
	if err := repo.Find(ctx, &book, query); err != nil {
		return err
	}
	if err := repo.Preload(ctx, &book, "author"); err != nil {
		return err
	}
	return repo.Transaction(ctx, func(ctx context.Context) error {
		book.Title = "REL for dummies"
		repo.MustUpdate(ctx, &book)
		repo.MustUpdate(ctx, &book, rel.Set("discount", false))
		return repo.Update(ctx, &book, rel.Dec("stock"))
	})
}
func Example ( ctx context . Context , repo rel . Repository ) error { var book Book if err := repo . Find ( ctx , & book , where . Eq ( " " , 1 ) ) ; err != nil { return err } query := rel . Select ( ) . Where ( where . Eq ( " " , 1 ) ) . Limit ( 1 ) if err := repo . Find ( ctx , & book , query ) ; err != nil { return err } if err := repo . Preload ( ctx , & book , " " ) ; err != nil { return err } return repo . Transaction ( ctx , func ( ctx context . Context ) error { book . Title = " " repo . MustUpdate ( ctx , & book ) repo . MustUpdate ( ctx , & book , rel . Set ( " " , false ) ) return repo . Update ( ctx , & book , rel . Dec ( " " ) ) } ) }
Example is an actual service function that run a complex business package.
Example is an actual service function that run a complex business package .
// Quickly find a book with id 1 using short alias. // Or use chainable query builder. // Convenient method to preload Book's Author. // Performs updates inside a transaction. // basic update using struct. // update only specific fields. // it even supports atomic inc/dec mutation.