func (p *MySQL) AddWithinTx(ctx context.Context, evt *outboxer.OutboxMessage, fn func(outboxer.ExecerContext) error) error {
	tx, err := p.conn.BeginTx(ctx, &sql.TxOptions{})
	if err != nil {
		return fmt.Errorf("transaction start failed: %w", err)
	}

	err = fn(tx)
	if err != nil {
		return err
	}

	// nolint
	query := fmt.Sprintf(`INSERT INTO %s (payload, options, headers) VALUES (?, ?, ?)`, p.EventStoreTable)
	if _, err := tx.ExecContext(ctx, query, evt.Payload, evt.Options, evt.Headers); err != nil {
		if err := tx.Rollback(); err != nil {
			return err
		}

		return fmt.Errorf("failed to insert message into the data store: %w", err)
	}

	if err := tx.Commit(); err != nil {
		return fmt.Errorf("transaction commit failed: %w", err)
	}

	return nil
}
// AddWithinTx creates a transaction and then tries to execute anything within it
AddWithinTx creates a transaction and then tries to execute anything within it
// AddWithinTx creates a transaction and then tries to execute anything within it
func (p *MySQL) AddWithinTx(ctx context.Context, evt *outboxer.OutboxMessage, fn func(outboxer.ExecerContext) error) error {
	tx, err := p.conn.BeginTx(ctx, &sql.TxOptions{})
	if err != nil {
		return fmt.Errorf("transaction start failed: %w", err)
	}
	err = fn(tx)
	if err != nil {
		return err
	}
	query := fmt.Sprintf(`INSERT INTO %s (payload, options, headers) VALUES (?, ?, ?)`, p.EventStoreTable)
	if _, err := tx.ExecContext(ctx, query, evt.Payload, evt.Options, evt.Headers); err != nil {
		if err := tx.Rollback(); err != nil {
			return err
		}
		return fmt.Errorf("failed to insert message into the data store: %w", err)
	}
	if err := tx.Commit(); err != nil {
		return fmt.Errorf("transaction commit failed: %w", err)
	}
	return nil
}
func ( p * MySQL ) AddWithinTx ( ctx context . Context , evt * outboxer . OutboxMessage , fn func ( outboxer . ExecerContext ) error ) error { tx , err := p . conn . BeginTx ( ctx , & sql . TxOptions { } ) if err != nil { return fmt . Errorf ( " " , err ) } err = fn ( tx ) if err != nil { return err } query := fmt . Sprintf ( `INSERT INTO %s (payload, options, headers) VALUES (?, ?, ?)` , p . EventStoreTable ) if _ , err := tx . ExecContext ( ctx , query , evt . Payload , evt . Options , evt . Headers ) ; err != nil { if err := tx . Rollback ( ) ; err != nil { return err } return fmt . Errorf ( " " , err ) } if err := tx . Commit ( ) ; err != nil { return fmt . Errorf ( " " , err ) } return nil }
AddWithinTx creates a transaction and then tries to execute anything within it
AddWithinTx creates a transaction and then tries to execute anything within it
// nolint