1package storage23import (4 "context"5 "database/sql"6)78// AddBeforeCommit appends a projection to this save's transaction. Projections9// run in registration order and the first error rolls back the complete save.10func (o *SaveOptions) AddBeforeCommit(next func(context.Context, *sql.Tx) error) {11 if next == nil {12 return13 }14 previous := o.BeforeCommit15 o.BeforeCommit = func(ctx context.Context, tx *sql.Tx) error {16 if previous != nil {17 if err := previous(ctx, tx); err != nil {18 return err19 }20 }21 return next(ctx, tx)22 }23}