observer

package
v0.58.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: AGPL-3.0 Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 []orm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query orm.Query,
	eventType orm.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 []orm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query orm.Query,
) error

DispatchCreated dispatches the created event.

func (*Dispatcher) DispatchCreating

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

DispatchCreating dispatches the creating event.

func (*Dispatcher) DispatchDeleted

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

DispatchDeleted dispatches the deleted event.

func (*Dispatcher) DispatchDeleting

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

DispatchDeleting dispatches the deleting event.

func (*Dispatcher) DispatchForceDeleted

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

DispatchForceDeleted dispatches the force deleted event.

func (*Dispatcher) DispatchForceDeleting

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

DispatchForceDeleting dispatches the force deleting event.

func (*Dispatcher) DispatchRestored

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

DispatchRestored dispatches the restored event.

func (*Dispatcher) DispatchRestoring

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

DispatchRestoring dispatches the restoring event.

func (*Dispatcher) DispatchRetrieved

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

DispatchRetrieved dispatches the retrieved event.

func (*Dispatcher) DispatchSaved

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

DispatchSaved dispatches the saved event.

func (*Dispatcher) DispatchSaving

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

DispatchSaving dispatches the saving event.

func (*Dispatcher) DispatchUpdated

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

DispatchUpdated dispatches the updated event.

func (*Dispatcher) DispatchUpdating

func (d *Dispatcher) DispatchUpdating(
	ctx context.Context,
	model any,
	observers []orm.ModelToObserver,
	original map[string]any,
	attributes map[string]any,
	dirty map[string]bool,
	query orm.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 orm.Query,
	eventType orm.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() orm.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() orm.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