changes.go 996 B

12345678910111213141516171819202122232425262728293031323334
  1. package memdb
  2. // Changes describes a set of mutations to memDB tables performed during a
  3. // transaction.
  4. type Changes []Change
  5. // Change describes a mutation to an object in a table.
  6. type Change struct {
  7. Table string
  8. Before interface{}
  9. After interface{}
  10. // primaryKey stores the raw key value from the primary index so that we can
  11. // de-duplicate multiple updates of the same object in the same transaction
  12. // but we don't expose this implementation detail to the consumer.
  13. primaryKey []byte
  14. }
  15. // Created returns true if the mutation describes a new object being inserted.
  16. func (m *Change) Created() bool {
  17. return m.Before == nil && m.After != nil
  18. }
  19. // Updated returns true if the mutation describes an existing object being
  20. // updated.
  21. func (m *Change) Updated() bool {
  22. return m.Before != nil && m.After != nil
  23. }
  24. // Deleted returns true if the mutation describes an existing object being
  25. // deleted.
  26. func (m *Change) Deleted() bool {
  27. return m.Before != nil && m.After == nil
  28. }