SQLiteEventStore

zio.blocks.projection.SQLiteEventStore
See theSQLiteEventStore companion object
final class SQLiteEventStore[E] extends EventStore[E]

An EventStore kept in a SQLite database.

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

Attributes

Companion
object
Source
EventStore.scala
Graph
Supertypes
trait EventStore[E]
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def append(entityId: String, event: E): Task[Long]

Appends event, recorded under the entity entityId, and returns its sequence number.

Appends event, recorded under the entity entityId, and returns its sequence number.

The event is stored first, and its EventEnvelope is then published to the hub returned by subscribe.

Value parameters

entityId

the entity the event belongs to, which a handler sees as ProjectionContext#entityId

event

the event to store

Attributes

Returns

the sequence number given to the event, greater than that of every event stored before it

Source
EventStore.scala
def readAll(tags: Set[String] = ...): ZStream[Any, Throwable, EventEnvelope[E]]

Streams every stored event, in order. The same as readFrom(0L, tags).

Streams every stored event, in order. The same as readFrom(0L, tags).

A schema rebuild uses it to replay all the events.

Value parameters

tags

the tags of the events to keep; the empty set, the default, keeps them all

Attributes

Source
EventStore.scala
def readFrom(afterSeq: Long, tags: Set[String] = ...): ZStream[Any, Throwable, EventEnvelope[E]]

Streams the stored events whose sequence number is greater than afterSeq, in order.

Streams the stored events whose sequence number is greater than afterSeq, in order.

The engine uses it to catch up from the last event it processed.

Value parameters

afterSeq

the sequence number to read after; 0 reads from the first event

tags

the tags of the events to keep; the empty set, the default, keeps them all

Attributes

Source
EventStore.scala

Concrete fields

val subscribe: Hub[EventEnvelope[E]]

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.

Attributes

Source
EventStore.scala

Attributes

Source
EventStore.scala