repository

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package repository provides data access for events.

Index

Constants

This section is empty.

Variables

View Source
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) GetEvent

func (r *PostgresEventRepository) GetEvent(ctx context.Context, eventID string) (*bus.Event, error)

GetEvent retrieves an event by its ID.

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.

func (*PostgresEventRepository) SaveEvent

func (r *PostgresEventRepository) SaveEvent(ctx context.Context, event bus.Event) error

SaveEvent persists an event to the database.

Jump to

Keyboard shortcuts

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