forked from zitadel/zitadel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventstore.go
47 lines (38 loc) · 1.36 KB
/
eventstore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package v1
import (
"context"
"database/sql"
"github.com/dennigogo/zitadel/internal/eventstore/v1/internal/repository"
z_sql "github.com/dennigogo/zitadel/internal/eventstore/v1/internal/repository/sql"
"github.com/dennigogo/zitadel/internal/eventstore/v1/models"
)
type Eventstore interface {
Health(ctx context.Context) error
FilterEvents(ctx context.Context, searchQuery *models.SearchQuery) (events []*models.Event, err error)
Subscribe(aggregates ...models.AggregateType) *Subscription
InstanceIDs(ctx context.Context, searchQuery *models.SearchQuery) ([]string, error)
}
var _ Eventstore = (*eventstore)(nil)
type eventstore struct {
repo repository.Repository
}
func Start(db *sql.DB) (Eventstore, error) {
return &eventstore{
repo: z_sql.Start(db),
}, nil
}
func (es *eventstore) FilterEvents(ctx context.Context, searchQuery *models.SearchQuery) ([]*models.Event, error) {
if err := searchQuery.Validate(); err != nil {
return nil, err
}
return es.repo.Filter(ctx, models.FactoryFromSearchQuery(searchQuery))
}
func (es *eventstore) Health(ctx context.Context) error {
return es.repo.Health(ctx)
}
func (es *eventstore) InstanceIDs(ctx context.Context, searchQuery *models.SearchQuery) ([]string, error) {
if err := searchQuery.Validate(); err != nil {
return nil, err
}
return es.repo.InstanceIDs(ctx, models.FactoryFromSearchQuery(searchQuery))
}