observer

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractModelAttributes

func ExtractModelAttributes(model any) map[string]any

ExtractModelAttributes extracts attributes from a model using reflection.

Types

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

Dispatcher handles event dispatching for model lifecycle events.

func NewDispatcher

func NewDispatcher(log log.Log) *Dispatcher

NewDispatcher creates a new Dispatcher instance.

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(
	ctx context.Context,
	model any,
	observers []contractsorm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
	eventType contractsorm.EventType,
) error

Dispatch dispatches an event to all registered observers for the given model.

func (*Dispatcher) DispatchCreated

func (d *Dispatcher) DispatchCreated(
	ctx context.Context,
	model any,
	observers []contractsorm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
) error

DispatchCreated dispatches the created event.

func (*Dispatcher) DispatchCreating

func (d *Dispatcher) DispatchCreating(
	ctx context.Context,
	model any,
	observers []contractsorm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
) error

DispatchCreating dispatches the creating event.

func (*Dispatcher) DispatchDeleted

func (d *Dispatcher) DispatchDeleted(
	ctx context.Context,
	model any,
	observers []contractsorm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
) error

DispatchDeleted dispatches the deleted event.

func (*Dispatcher) DispatchDeleting

func (d *Dispatcher) DispatchDeleting(
	ctx context.Context,
	model any,
	observers []contractsorm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
) error

DispatchDeleting dispatches the deleting event.

func (*Dispatcher) DispatchForceDeleted

func (d *Dispatcher) DispatchForceDeleted(
	ctx context.Context,
	model any,
	observers []contractsorm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
) error

DispatchForceDeleted dispatches the force deleted event.

func (*Dispatcher) DispatchForceDeleting

func (d *Dispatcher) DispatchForceDeleting(
	ctx context.Context,
	model any,
	observers []contractsorm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
) error

DispatchForceDeleting dispatches the force deleting event.

func (*Dispatcher) DispatchRestored

func (d *Dispatcher) DispatchRestored(
	ctx context.Context,
	model any,
	observers []contractsorm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
) error

DispatchRestored dispatches the restored event.

func (*Dispatcher) DispatchRestoring

func (d *Dispatcher) DispatchRestoring(
	ctx context.Context,
	model any,
	observers []contractsorm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
) error

DispatchRestoring dispatches the restoring event.

func (*Dispatcher) DispatchRetrieved

func (d *Dispatcher) DispatchRetrieved(
	ctx context.Context,
	model any,
	observers []contractsorm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
) error

DispatchRetrieved dispatches the retrieved event.

func (*Dispatcher) DispatchSaved

func (d *Dispatcher) DispatchSaved(
	ctx context.Context,
	model any,
	observers []contractsorm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
) error

DispatchSaved dispatches the saved event.

func (*Dispatcher) DispatchSaving

func (d *Dispatcher) DispatchSaving(
	ctx context.Context,
	model any,
	observers []contractsorm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
) error

DispatchSaving dispatches the saving event.

func (*Dispatcher) DispatchUpdated

func (d *Dispatcher) DispatchUpdated(
	ctx context.Context,
	model any,
	observers []contractsorm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
) error

DispatchUpdated dispatches the updated event.

func (*Dispatcher) DispatchUpdating

func (d *Dispatcher) DispatchUpdating(
	ctx context.Context,
	model any,
	observers []contractsorm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
) error

DispatchUpdating dispatches the updating event.

type Event

type Event struct {
	// contains filtered or unexported fields
}

Event implements the Event interface for model lifecycle events.

func NewEvent

func NewEvent(
	ctx context.Context,
	model any,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query contractsorm.Query,
	eventType contractsorm.EventType,
) *Event

NewEvent creates a new Event instance.

func (*Event) Context

func (e *Event) Context() context.Context

Context returns the event context.

func (*Event) EventType

func (e *Event) EventType() contractsorm.EventType

EventType returns the event type.

func (*Event) GetAttribute

func (e *Event) GetAttribute(key string) any

GetAttribute returns the attribute value for the given key.

func (*Event) GetOriginal

func (e *Event) GetOriginal(key string, def ...any) any

GetOriginal returns the original attribute value for the given key.

func (*Event) IsClean

func (e *Event) IsClean(columns ...string) bool

IsClean returns true if the given column is clean (not dirty).

func (*Event) IsDirty

func (e *Event) IsDirty(columns ...string) bool

IsDirty returns true if the given column is dirty (has been modified).

func (*Event) Model

func (e *Event) Model() any

Model returns the model instance.

func (*Event) Query

func (e *Event) Query() contractsorm.Query

Query returns the query instance.

func (*Event) SetAttribute

func (e *Event) SetAttribute(key string, value any)

SetAttribute sets the attribute value for the given key.

Jump to

Keyboard shortcuts

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