Skip to content

update panic recover in Twowaysql.Transaction. #5

@future-taga

Description

@future-taga

Improved recover and automatic rollback in the panic

func (t *Twowaysql) Transaction(ctx context.Context, fn func(tx TwowaysqlTx) error) error {
tx, err := t.Begin(ctx)
if err != nil {
return err
}
if err := fn(*tx); err != nil {
if rerr := tx.Rollback(); rerr != nil {
return fmt.Errorf("failed rollback %v: %w", rerr, err)
}
return err
}
if err := tx.Commit(); err != nil {
return err
}
return nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions