Each event is a row of the events table, with the columns seq, tag, payload, ts and entityId. seq is the primary key and gives the sequence number. tag is the @eventTag number of the event's case, or else the case's name; for an event type that is not a sealed trait, it is the type's own @eventTag number or name. payload is the event encoded as JSON, and ts is the time it was appended, in milliseconds. An index on tag and seq serves filtered reads.
The store knows the tags of E through a TagInfo. When a case was renamed, a read that asks for the new tag also returns the events saved under the old one, decodes them as the renamed case, and reports them under the new tag.
A read opens its own connection and pulls the rows through a cursor as the stream is consumed. An event whose payload cannot be decoded fails the stream.
The constructor is private: create a store with the factories of the companion object, which also create the table and its index if they are missing.
Value parameters
subscribe
the hub that every appended event is published to
tagInfo
the tags of E, and the old tags that were renamed to them
The hub that every appended event is published to.
The hub that every appended event is published to.
Despite its name, this does not subscribe. Call subscribe on the returned hub, inside a Scope, to receive the events appended from then on. The events stored before that are read with readFrom.