EventStore.link_to_stream
link_to_stream
, go back to EventStore module for more information.
Specs
link_to_stream( stream_uuid :: String.t(), expected_version(), events :: [EventStore.RecordedEvent.t()] | [non_neg_integer()], opts :: options() ) :: :ok | {:error, :cannot_append_to_all_stream} | {:error, :stream_exists} | {:error, :stream_not_found} | {:error, :wrong_expected_version} | {:error, :stream_deleted} | {:error, reason :: term()}
Link one or more existing events to another stream.
Allows you to construct streams containing events already appended to any other stream. This is more efficient than copying events between streams since only a reference to the existing event is created.
stream_uuid
is used to uniquely identify the target stream.expected_version
is used for optimistic concurrency checks. You can provide a non-negative integer to specify the expected stream version. This is used to ensure you can only append to the stream if it is at exactly that version.You can also provide one of the following values to affect the concurrency check behaviour:
:any_version
- No concurrency checking; allow any stream version (including no stream).:no_stream
- Ensure the stream does not exist.:stream_exists
- Ensure the stream exists.
events_or_event_ids
is a list of%EventStore.EventData{}
structs or event ids.opts
an optional keyword list containing:name
the name of the event store if provided tostart_link/1
.timeout
an optional timeout for the database transaction, in milliseconds. Defaults to 15,000ms.
Returns :ok
on success, or an {:error, reason}
tagged tuple. The returned
error may be due to one of the following reasons:
{:error, :wrong_expected_version}
when the actual stream version differs from the provided expected version.{:error, :stream_exists}
when the stream exists, but expected version was:no_stream
.{:error, :stream_not_found}
when the stream does not exist, but expected version was:stream_exists
.