entitydiff

package
v1.0.0-beta.225 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiffByID

func DiffByID[T Entity](input DiffByIDInput[T]) error

DiffByID compares the expected state with the db state by ID.

The callback functions are used to allow for custom handling of the diff entries.

The call does not compare the entities themselves, it only compares the IDs. Can be used for entities that have child entities.

Types

type Diff

type Diff[T Entity] struct {
	Update []DiffUpdate[T]
	Create []T
	Delete []T
}

func DiffByIDEqualer

func DiffByIDEqualer[T EqualerEntity[T]](expectedState, dbState []T) Diff[T]

DiffByIDEqualer compares the expected state with the db state by ID.

This call uses the Equal method of the entity to compare the expected state with the db state in case of updates.

Should be used for entities that do not have any child entities.

func Union

func Union[T Entity](diffs ...Diff[T]) Diff[T]

func (*Diff[T]) Append

func (d *Diff[T]) Append(a Diff[T]) Diff[T]

func (*Diff[T]) IsEmpty

func (d *Diff[T]) IsEmpty() bool

func (*Diff[T]) NeedsCreate

func (d *Diff[T]) NeedsCreate(item ...T)

func (*Diff[T]) NeedsDelete

func (d *Diff[T]) NeedsDelete(item ...T)

func (*Diff[T]) NeedsUpdate

func (d *Diff[T]) NeedsUpdate(item ...DiffUpdate[T])

type DiffByIDInput

type DiffByIDInput[T Entity] struct {
	DBState       []T
	ExpectedState []T

	HandleDelete func(item T) error
	HandleCreate func(item T) error
	HandleUpdate func(item DiffUpdate[T]) error
}

type DiffUpdate

type DiffUpdate[T Entity] struct {
	// PersistedState is the persisted state of the entity (e.g. in database or any storage), if empty there is no persisted state
	PersistedState T
	// ExpectedState is the expected state of the entity (e.g. after the changes done by the backend)
	ExpectedState T
}

type Entity

type Entity interface {
	GetID() string
	IsDeleted() bool
}

type EqualerEntity

type EqualerEntity[T any] interface {
	Entity
	equal.Equaler[T]
}

type EqualerNestedEntity

type EqualerNestedEntity[T EqualerEntity[T], P Entity] struct {
	Entity T
	Parent P
}

func NewEqualersWithParent

func NewEqualersWithParent[T EqualerEntity[T], P Entity](entity []T, parent P) []EqualerNestedEntity[T, P]

func (EqualerNestedEntity[T, P]) Equal

func (w EqualerNestedEntity[T, P]) Equal(other EqualerNestedEntity[T, P]) bool

func (EqualerNestedEntity[T, P]) GetID

func (w EqualerNestedEntity[T, P]) GetID() string

func (EqualerNestedEntity[T, P]) IsDeleted

func (w EqualerNestedEntity[T, P]) IsDeleted() bool

type NestedEntity

type NestedEntity[T Entity, P Entity] struct {
	Entity T
	Parent P
}

func (NestedEntity[T, P]) GetID

func (w NestedEntity[T, P]) GetID() string

func (NestedEntity[T, P]) IsDeleted

func (w NestedEntity[T, P]) IsDeleted() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL