ProjectionStore

zio.blocks.projection.ProjectionStore
trait ProjectionStore[A]

Where the rows of one read model A are kept.

A store holds the rows, each under the entity ID read from its ID field (see EntityPath), and two values the engine keeps next to them: the watermark, which is the sequence number of the last event applied to the rows, and the schema hash, a fingerprint of the shape of A that tells the engine when the rows are out of date.

The engine applies the ProjectionAction that a handler returns with one of these methods, and reads a row back with findById. SQLiteProjectionStore keeps the rows in a SQLite file, and testing.InMemoryProjectionStore keeps them in memory, for tests.

Type parameters

A

the type of a row: a case class with an ID field

Attributes

Source
ProjectionStore.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

def delete(entityId: String): Task[Unit]

Removes the row with the ID entityId, if there is one.

Removes the row with the ID entityId, if there is one.

Value parameters

entityId

the ID of the row to remove

Attributes

Source
ProjectionStore.scala
def findById(entityId: String): Task[Option[A]]

Reads the row with the ID entityId.

Reads the row with the ID entityId.

Value parameters

entityId

the ID of the row to read

Attributes

Returns

the row, or None if there is none

Source
ProjectionStore.scala
def getLastProcessedSeq: Task[Long]

The watermark: the sequence number of the last event applied to the rows, or 0 if none has been applied yet. The engine reads it at startup, to continue after that event.

The watermark: the sequence number of the last event applied to the rows, or 0 if none has been applied yet. The engine reads it at startup, to continue after that event.

Attributes

Source
ProjectionStore.scala
def getSchemaHash: Task[Option[String]]

The schema hash saved with the rows, or None if none has been saved yet, as in a new store.

The schema hash saved with the rows, or None if none has been saved yet, as in a new store.

Attributes

Source
ProjectionStore.scala
def insert(a: A): Task[Unit]

Adds a as a new row, under the ID read from its ID field.

Adds a as a new row, under the ID read from its ID field.

Fails if a row with that ID already exists.

Value parameters

a

the row to add

Attributes

Source
ProjectionStore.scala
def truncate: Task[Unit]

Removes every row. The watermark and the schema hash are kept.

Removes every row. The watermark and the schema hash are kept.

Attributes

Source
ProjectionStore.scala
def updateFields(entityId: String, updates: Chunk[FieldUpdate]): Task[Unit]

Applies updates to the row with the ID entityId, as one change.

Applies updates to the row with the ID entityId, as one change.

If there is no such row yet, it is first created with a default value in each column, so that, for example, the first increment of a counter gives 1. The updates are applied in order.

Value parameters

entityId

the ID of the row to change

updates

the changes to apply; their field names are column names, in snake_case, such as user_count. An empty chunk does nothing.

Attributes

Source
ProjectionStore.scala
def updateLastProcessedSeq(seq: Long): Task[Unit]

Saves seq as the watermark. The engine calls it after it applies an event.

Saves seq as the watermark. The engine calls it after it applies an event.

Value parameters

seq

the sequence number of the last event applied to the rows

Attributes

Source
ProjectionStore.scala
def updateSchemaHash(hash: String): Task[Unit]

Saves hash as the schema hash of the rows. The engine calls it once the rows match the current shape of A.

Saves hash as the schema hash of the rows. The engine calls it once the rows match the current shape of A.

Value parameters

hash

the fingerprint of the shape of A, from SchemaHash

Attributes

Source
ProjectionStore.scala
def upsert(a: A): Task[Unit]

Adds a as a new row, or replaces the row that has the same ID.

Adds a as a new row, or replaces the row that has the same ID.

Value parameters

a

the row to add or replace

Attributes

Source
ProjectionStore.scala

Concrete methods

def addColumn(columnName: String, sqlType: String): Task[Unit]

Adds the column columnName, if the rows do not have it yet. The migration shortcut calls it for each field that a migration adds.

Adds the column columnName, if the rows do not have it yet. The migration shortcut calls it for each field that a migration adds.

The default does nothing. SQLiteProjectionStore checks the name against ^[a-zA-Z_][a-zA-Z0-9_]*$ and runs ALTER TABLE ... ADD COLUMN.

Value parameters

columnName

the name of the column, in snake_case

sqlType

the SQL type of the column, such as TEXT

Attributes

Source
ProjectionStore.scala
def recreateTable(): Task[Unit]

Starts the rows over for a new shape of A. A full rebuild calls it before it replays the events.

Starts the rows over for a new shape of A. A full rebuild calls it before it replays the events.

The default only removes the rows with truncate. SQLiteProjectionStore drops the table and creates it again for the current shape of A.

Attributes

Source
ProjectionStore.scala