github.com/goravel/framework@v1.13.9/contracts/database/orm/events.go (about)

     1  package orm
     2  
     3  import (
     4  	"context"
     5  )
     6  
     7  type EventType string
     8  
     9  const EventRetrieved EventType = "retrieved"
    10  const EventCreating EventType = "creating"
    11  const EventCreated EventType = "created"
    12  const EventUpdating EventType = "updating"
    13  const EventUpdated EventType = "Updated"
    14  const EventSaving EventType = "saving"
    15  const EventSaved EventType = "saved"
    16  const EventDeleting EventType = "deleting"
    17  const EventDeleted EventType = "deleted"
    18  const EventForceDeleting EventType = "force_deleting"
    19  const EventForceDeleted EventType = "force_deleted"
    20  
    21  type Event interface {
    22  	// Context returns the event context.
    23  	Context() context.Context
    24  	// GetAttribute returns the attribute value for the given key.
    25  	GetAttribute(key string) any
    26  	// GetOriginal returns the original attribute value for the given key.
    27  	GetOriginal(key string, def ...any) any
    28  	// IsDirty returns true if the given column is dirty.
    29  	IsDirty(columns ...string) bool
    30  	// IsClean returns true if the given column is clean.
    31  	IsClean(columns ...string) bool
    32  	// Query returns the query instance.
    33  	Query() Query
    34  	// SetAttribute sets the attribute value for the given key.
    35  	SetAttribute(key string, value any)
    36  }
    37  
    38  type DispatchesEvents interface {
    39  	// DispatchesEvents returns the event handlers.
    40  	DispatchesEvents() map[EventType]func(Event) error
    41  }