func (s *Store) UpdateMatching(dataType interface{}, query *Query, update func(record interface{}) error) error {
	err := s.Badger().Update(func(tx *badger.Txn) error {
		return s.TxUpdateMatching(tx, dataType, query, update)
	})
	if err == badger.ErrConflict {
		return s.UpdateMatching(dataType, query, update)
	}
	return err
}
UpdateMatching runs the update function for every record that match the passed in query
Note that the type  of record in the update func always has to be a pointer
package badgerhold
import (
	"errors"
	"reflect"
	"github.com/dgraph-io/badger/v3"
)
var ErrKeyExists = errors.New("This Key already exists in badgerhold for this type")
var ErrUniqueExists = errors.New("This value cannot be written due to the unique constraint on the field")
type sequence struct{}
func NextSequence() interface{} {
	return sequence{}
}
func (s *Store) Insert(key, data interface{}) error {
	err := s.Badger().Update(func(tx *badger.Txn) error {
		return s.TxInsert(tx, key, data)
	})
	if err == badger.ErrConflict {
		return s.Insert(key, data)
	}
	return err
}
func (s *Store) TxInsert(tx *badger.Txn, key, data interface{}) error {
	storer := s.newStorer(data)
	var err error
	if _, ok := key.(sequence); ok {
		key, err = s.getSequence(storer.Type())
		if err != nil {
			return err
		}
	}
	gk, err := s.encodeKey(key, storer.Type())
	if err != nil {
		return err
	}
	_, err = tx.Get(gk)
	if err != badger.ErrKeyNotFound {
		return ErrKeyExists
	}
	value, err := s.encode(data)
	if err != nil {
		return err
	}
	err = tx.Set(gk, value)
	if err != nil {
		return err
	}
	err = s.indexAdd(storer, tx, gk, data)
	if err != nil {
		return err
	}
	dataVal := reflect.Indirect(reflect.ValueOf(data))
	if !dataVal.CanSet() {
		return nil
	}
	if keyField, ok := getKeyField(dataVal.Type()); ok {
		fieldValue := dataVal.FieldByName(keyField.Name)
		keyValue := reflect.ValueOf(key)
		if keyValue.Type() != keyField.Type {
			return nil
		}
		if !fieldValue.CanSet() {
			return nil
		}
		if !reflect.DeepEqual(fieldValue.Interface(), reflect.Zero(keyField.Type).Interface()) {
			return nil
		}
		fieldValue.Set(keyValue)
	}
	return nil
}
func (s *Store) Update(key interface{}, data interface{}) error {
	err := s.Badger().Update(func(tx *badger.Txn) error {
		return s.TxUpdate(tx, key, data)
	})
	if err == badger.ErrConflict {
		return s.Update(key, data)
	}
	return err
}
func (s *Store) TxUpdate(tx *badger.Txn, key interface{}, data interface{}) error {
	storer := s.newStorer(data)
	gk, err := s.encodeKey(key, storer.Type())
	if err != nil {
		return err
	}
	existingItem, err := tx.Get(gk)
	if err == badger.ErrKeyNotFound {
		return ErrNotFound
	}
	if err != nil {
		return err
	}
	existingVal := newElemType(data)
	err = existingItem.Value(func(existing []byte) error {
		return s.decode(existing, existingVal)
	})
	if err != nil {
		return err
	}
	err = s.indexDelete(storer, tx, gk, existingVal)
	if err != nil {
		return err
	}
	value, err := s.encode(data)
	if err != nil {
		return err
	}
	err = tx.Set(gk, value)
	if err != nil {
		return err
	}
	return s.indexAdd(storer, tx, gk, data)
}
func (s *Store) Upsert(key interface{}, data interface{}) error {
	err := s.Badger().Update(func(tx *badger.Txn) error {
		return s.TxUpsert(tx, key, data)
	})
	if err == badger.ErrConflict {
		return s.Upsert(key, data)
	}
	return err
}
func (s *Store) TxUpsert(tx *badger.Txn, key interface{}, data interface{}) error {
	storer := s.newStorer(data)
	gk, err := s.encodeKey(key, storer.Type())
	if err != nil {
		return err
	}
	existingItem, err := tx.Get(gk)
	if err == nil {
		existingVal := newElemType(data)
		err = existingItem.Value(func(existing []byte) error {
			return s.decode(existing, existingVal)
		})
		if err != nil {
			return err
		}
		err = s.indexDelete(storer, tx, gk, existingVal)
		if err != nil {
			return err
		}
	} else if err != badger.ErrKeyNotFound {
		return err
	}
	value, err := s.encode(data)
	if err != nil {
		return err
	}
	err = tx.Set(gk, value)
	if err != nil {
		return err
	}
	return s.indexAdd(storer, tx, gk, data)
}