Documentation
¶
Overview ¶
Package repository provides data access for events.
Index ¶
- Variables
- type EventFilter
- type EventRepository
- type PostgresEventRepository
- func (r *PostgresEventRepository) CountEvents(ctx context.Context, filter EventFilter) (int64, error)
- func (r *PostgresEventRepository) CreateEventsTable(ctx context.Context) error
- func (r *PostgresEventRepository) DeleteOldEvents(ctx context.Context, before time.Time) (int64, error)
- func (r *PostgresEventRepository) GetEvent(ctx context.Context, eventID string) (*bus.Event, error)
- func (r *PostgresEventRepository) GetEventsBySource(ctx context.Context, source string, limit int) ([]bus.Event, error)
- func (r *PostgresEventRepository) GetEventsByType(ctx context.Context, eventType bus.EventType, limit int) ([]bus.Event, error)
- func (r *PostgresEventRepository) ListEvents(ctx context.Context, filter EventFilter) ([]bus.Event, error)
- func (r *PostgresEventRepository) SaveEvent(ctx context.Context, event bus.Event) error
Constants ¶
This section is empty.
Variables ¶
var ErrEventNotFound = errors.New("event not found")
ErrEventNotFound is returned when an event is not found.
Functions ¶
This section is empty.
Types ¶
type EventFilter ¶
type EventFilter struct {
Types []bus.EventType
Sources []string
StartTime *time.Time
EndTime *time.Time
Limit int
Offset int
}
EventFilter specifies criteria for filtering events.
type EventRepository ¶
type EventRepository interface {
// SaveEvent persists an event to the database.
SaveEvent(ctx context.Context, event bus.Event) error
// GetEvent retrieves an event by its ID.
GetEvent(ctx context.Context, eventID string) (*bus.Event, error)
// ListEvents retrieves events matching the filter criteria.
ListEvents(ctx context.Context, filter EventFilter) ([]bus.Event, error)
// GetEventsByType retrieves events of a specific type.
GetEventsByType(ctx context.Context, eventType bus.EventType, limit int) ([]bus.Event, error)
// GetEventsBySource retrieves events from a specific source.
GetEventsBySource(ctx context.Context, source string, limit int) ([]bus.Event, error)
// CountEvents returns the total count of events matching the filter.
CountEvents(ctx context.Context, filter EventFilter) (int64, error)
// DeleteOldEvents removes events older than the specified time.
DeleteOldEvents(ctx context.Context, before time.Time) (int64, error)
}
EventRepository defines the interface for event persistence.
type PostgresEventRepository ¶
type PostgresEventRepository struct {
// contains filtered or unexported fields
}
PostgresEventRepository implements EventRepository using PostgreSQL.
func NewPostgresEventRepository ¶
func NewPostgresEventRepository(db *sql.DB) *PostgresEventRepository
NewPostgresEventRepository creates a new PostgresEventRepository.
func (*PostgresEventRepository) CountEvents ¶
func (r *PostgresEventRepository) CountEvents(ctx context.Context, filter EventFilter) (int64, error)
CountEvents returns the total count of events matching the filter.
func (*PostgresEventRepository) CreateEventsTable ¶
func (r *PostgresEventRepository) CreateEventsTable(ctx context.Context) error
CreateEventsTable creates the events table if it doesn't exist.
func (*PostgresEventRepository) DeleteOldEvents ¶
func (r *PostgresEventRepository) DeleteOldEvents(ctx context.Context, before time.Time) (int64, error)
DeleteOldEvents removes events older than the specified time.
func (*PostgresEventRepository) GetEventsBySource ¶
func (r *PostgresEventRepository) GetEventsBySource(ctx context.Context, source string, limit int) ([]bus.Event, error)
GetEventsBySource retrieves events from a specific source.
func (*PostgresEventRepository) GetEventsByType ¶
func (r *PostgresEventRepository) GetEventsByType(ctx context.Context, eventType bus.EventType, limit int) ([]bus.Event, error)
GetEventsByType retrieves events of a specific type.
func (*PostgresEventRepository) ListEvents ¶
func (r *PostgresEventRepository) ListEvents(ctx context.Context, filter EventFilter) ([]bus.Event, error)
ListEvents retrieves events matching the filter criteria.