2022-10-13 15:32:25 -06:00
|
|
|
// package driver defines interfaces to be used by driver implementations.
|
2022-08-04 14:37:51 -06:00
|
|
|
package driver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-07-12 17:35:02 -06:00
|
|
|
"go.sour.is/ev/pkg/event"
|
2022-08-04 14:37:51 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
type Driver interface {
|
2022-08-09 16:23:33 -06:00
|
|
|
Open(ctx context.Context, dsn string) (Driver, error)
|
|
|
|
EventLog(ctx context.Context, streamID string) (EventLog, error)
|
2022-08-04 14:37:51 -06:00
|
|
|
}
|
|
|
|
|
2022-08-09 16:23:33 -06:00
|
|
|
type EventLog interface {
|
2022-10-25 20:15:57 -06:00
|
|
|
Read(ctx context.Context, after, count int64) (event.Events, error)
|
2022-10-30 09:18:08 -06:00
|
|
|
ReadN(ctx context.Context, index ...uint64) (event.Events, error)
|
2022-08-09 16:23:33 -06:00
|
|
|
Append(ctx context.Context, events event.Events, version uint64) (uint64, error)
|
2022-08-14 10:04:15 -06:00
|
|
|
FirstIndex(context.Context) (uint64, error)
|
|
|
|
LastIndex(context.Context) (uint64, error)
|
2022-09-30 14:56:10 -06:00
|
|
|
}
|
2022-12-19 10:50:38 -07:00
|
|
|
|
2022-11-20 10:15:51 -07:00
|
|
|
type EventLogWithTruncate interface {
|
|
|
|
Truncate(context.Context, int64) error
|
|
|
|
}
|
|
|
|
|
2022-09-30 14:56:10 -06:00
|
|
|
type EventLogWithUpdate interface {
|
2022-08-14 10:04:15 -06:00
|
|
|
LoadForUpdate(context.Context, event.Aggregate, func(context.Context, event.Aggregate) error) (uint64, error)
|
2022-08-09 16:23:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type Subscription interface {
|
2022-11-23 13:51:55 -07:00
|
|
|
Recv(context.Context) <-chan bool
|
2022-08-09 16:23:33 -06:00
|
|
|
Events(context.Context) (event.Events, error)
|
|
|
|
Close(context.Context) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type EventStream interface {
|
2022-08-10 10:09:58 -06:00
|
|
|
Subscribe(ctx context.Context, streamID string, start int64) (Subscription, error)
|
2022-08-09 16:23:33 -06:00
|
|
|
Send(ctx context.Context, streamID string, events event.Events) error
|
2022-08-04 14:37:51 -06:00
|
|
|
}
|