feat: add memstore driver

This commit is contained in:
Jon Lundy
2022-08-04 21:07:10 -06:00
parent 1010657a02
commit 189cb5c968
5 changed files with 165 additions and 7 deletions

View File

@@ -54,7 +54,7 @@ func (lis Events) SetStreamID(streamID string) {
}
func (lis Events) First() Event {
if len(lis) == 0 {
return nil
return nilEvent
}
return lis[0]
}
@@ -64,6 +64,12 @@ func (lis Events) Rest() Events {
}
return lis[1:]
}
func (lis Events) Last() Event {
if len(lis) == 0 {
return nilEvent
}
return lis[len(lis)-1]
}
func (lis Events) MarshalText() ([]byte, error) {
b := &bytes.Buffer{}
for i := range lis {
@@ -118,6 +124,7 @@ func SetPosition(e Event, i uint64) {
meta.Position = i
e.SetEventMeta(meta)
}
type Meta struct {
EventID ulid.ULID
StreamID string
@@ -127,3 +134,12 @@ type Meta struct {
func (m Meta) Time() time.Time {
return ulid.Time(m.EventID.Time())
}
type _nilEvent struct{}
func (_nilEvent) EventMeta() Meta {
return Meta{}
}
func (_nilEvent) SetEventMeta(eventMeta Meta) {}
var nilEvent _nilEvent