Streams

trait Streams[F[_]]

API for interacting with streams in EventStoreDB.

122Main operations122

  • subscribing to the global stream or an individual stream.
  • reading from the global stream or an individual stream.
  • appending event data to an existing stream or creating a new stream.
  • deleting events from a stream.
Type Params
F

the effect type in which Streams operates.

Companion
object
class Object
trait Matchable
class Any

Value members

Abstract methods

def appendToStream(streamId: StreamId, expectedState: StreamState, data: NonEmptyList[EventData]): F[WriteResult]

Appends EventData to a stream and returns WriteResult with current positions of the stream after a successful operation. Failure to fulfill the expected state is manifested by raising sec.api.exceptions.WrongExpectedState.

Appends EventData to a stream and returns WriteResult with current positions of the stream after a successful operation. Failure to fulfill the expected state is manifested by raising sec.api.exceptions.WrongExpectedState.

Value Params
data

event data to be appended to the stream. See EventData.

expectedState

the state that the stream is expected to in. See StreamState for details.

streamId

the id of the stream to append to.

See also

https://ahjohannessen.github.io/sec/docs/writing for details about appending to a stream.

def delete(streamId: StreamId, expectedState: StreamState): F[DeleteResult]

Deletes a stream and returns DeleteResult with current log position after a successful operation. Failure to fulfill the expected stated is manifested by raising sec.api.exceptions.WrongExpectedState.

Deletes a stream and returns DeleteResult with current log position after a successful operation. Failure to fulfill the expected stated is manifested by raising sec.api.exceptions.WrongExpectedState.

Value Params
expectedState

the state that the stream is expected to in. See StreamState for details.

streamId

the id of the stream to delete.

See also

https://ahjohannessen.github.io/sec/docs/deleting for details about what it means to delete a stream.

Note

Deleted streams can be recreated.

def readAll(from: LogPosition, direction: Direction, maxCount: Long, resolveLinkTos: Boolean): Stream[F, AllEvent]

Read events from the global stream, sec.StreamId.All.

Read events from the global stream, sec.StreamId.All.

Value Params
direction

whether to read forwards or backwards.

from

log position to read from.

maxCount

limits maximum events returned.

resolveLinkTos

whether to resolve EventType.LinkTo events automatically.

Returns

a Stream that emits AllEvent values.

def readStream(streamId: StreamId, from: StreamPosition, direction: Direction, maxCount: Long, resolveLinkTos: Boolean): Stream[F, StreamEvent]

Read events from an individual stream. A sec.api.exceptions.StreamNotFound is raised when the stream does not exist.

Read events from an individual stream. A sec.api.exceptions.StreamNotFound is raised when the stream does not exist.

Value Params
direction

whether to read forwards or backwards.

from

stream position to read from.

maxCount

limits maximum events returned.

resolveLinkTos

whether to resolve EventType.LinkTo events automatically.

streamId

the id of the stream to subscribe to.

Returns

a Stream that emits StreamEvent values.

def subscribeToAll(exclusiveFrom: Option[LogPosition], resolveLinkTos: Boolean): Stream[F, AllEvent]

Subscribes to the global stream, StreamId.All.

Subscribes to the global stream, StreamId.All.

Value Params
exclusiveFrom

position to start from. Use None to subscribe from the beginning.

resolveLinkTos

whether to resolve EventType.LinkTo events automatically.

Returns

a Stream that emits AllEvent values.

def subscribeToAll(exclusiveFrom: Option[LogPosition], filterOptions: SubscriptionFilterOptions, resolveLinkTos: Boolean): Stream[F, Either[Checkpoint, AllEvent]]

Subscribes to the global stream, StreamId.All using a subscription filter.

Subscribes to the global stream, StreamId.All using a subscription filter.

Value Params
exclusiveFrom

log position to start from. Use None to subscribe from the beginning.

filterOptions

to use when subscribing - See sec.api.SubscriptionFilterOptions.

resolveLinkTos

whether to resolve EventType.LinkTo events automatically.

Returns

a Stream that emits either Checkpoint or AllEvent values. How frequent Checkpoint is emitted depends on filterOptions.

def subscribeToStream(streamId: StreamId, exclusiveFrom: Option[StreamPosition], resolveLinkTos: Boolean): Stream[F, StreamEvent]

Subscribes to an individual stream.

Subscribes to an individual stream.

Value Params
exclusiveFrom

stream position to start from. Use None to subscribe from the beginning.

resolveLinkTos

whether to resolve EventType.LinkTo events automatically.

streamId

the id of the stream to subscribe to.

Returns

a Stream that emits StreamEvent values.

def tombstone(streamId: StreamId, expectedState: StreamState): F[TombstoneResult]

Tombstones a stream and returns TombstoneResult with current log position after a successful operation. Failure to fulfill the expected stated is manifested by raising sec.api.exceptions.WrongExpectedState.

Tombstones a stream and returns TombstoneResult with current log position after a successful operation. Failure to fulfill the expected stated is manifested by raising sec.api.exceptions.WrongExpectedState.

Value Params
expectedState

the state that the stream is expected to in. See StreamState for details.

streamId

the id of the stream to delete.

See also

https://ahjohannessen.github.io/sec/docs/deleting for details about what it means to tombstone a stream.

Note

Tombstoned streams can never be recreated.

def withCredentials(creds: UserCredentials): Streams[F]

Returns an instance that uses provided UserCredentials. This is useful when an operation requires different credentials from what is provided through configuration.

Returns an instance that uses provided UserCredentials. This is useful when an operation requires different credentials from what is provided through configuration.

Value Params
creds

Custom user credentials to use.