uow

package
v0.0.0-...-cada856 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 1 Imported by: 0

README

Unit of Work

The Unit of Work is a pattern that allows you to manage the state of your entities and commit them to the database in a single operation. It is a pattern that is often used in conjunction with the Repository pattern.

Features

  • Nested Transactional Use Cases
  • Spreading of Knowledge about Transactions
  • No boilerplate code
  • Database Agnostic
  • Easy to use/understand
  • Easy to test/mock
  • Easy to extend

References

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Query

type Query[T any] struct {
	UnitOfWork[T]

	New      []T
	Modified []T
	Deleted  []T
	// contains filtered or unexported fields
}

func New

func New[T any](ctx context.Context, unitOfWork UnitOfWork[T]) *Query[T]

func (*Query[T]) Commit

func (q *Query[T]) Commit() error

func (*Query[T]) RegisterClean

func (q *Query[T]) RegisterClean(_ ...T) error

func (*Query[T]) RegisterDeleted

func (q *Query[T]) RegisterDeleted(entity ...T) error

func (*Query[T]) RegisterDirty

func (q *Query[T]) RegisterDirty(entity ...T) error

func (*Query[T]) RegisterNew

func (q *Query[T]) RegisterNew(entity ...T) error

func (*Query[T]) Rollback

func (q *Query[T]) Rollback() error

type UnitOfWork

type UnitOfWork[T any] interface {
	RegisterNew(in ...T) error
	RegisterDirty(in ...T) error
	RegisterClean(in ...T) error
	RegisterDeleted(in ...T) error

	Commit(ctx context.Context) error
	Rollback(ctx context.Context) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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