eventastic-0.1.0 has been yanked.
Eventastic
This is an opinionated fork of Eventually-rs.
Eventastic enforces the use of transactions, handles idempotency and removes command handling abstractions.
Examples
See full examples in examples/bank
// Setup postgres repo
let connection_options =
from_str?;
let pool_options = default;
let repository = new.await?;
// Start transaction
let mut transaction = repository.transaction.await?;
let account_id = new_v4;
let event_id = new_v4;
let add_event_id = new_v4;
// Open bank account
let event = Open;
let mut account = record_new?;
// Add funds to newly created event
let add_event = Add;
// Record takes in the transaction, as it does idempotency checks with the db.
account
.record_that
.await?;
// Save uncommitted events in the db.
transaction.store.await?;
// Since we have access to the transaction
// We could use a transactional outbox to store our side effects
// Commit the transaction
transaction.commit.await?;
// Get the aggregate from the db
let mut transaction = repository.transaction.await?;
let mut account: = transaction.get.await?;
assert_eq!;
// Trying to apply the same event id but with different content gives us an IdempotencyError
let changed_add_event = Add;
let err = account
.record_that
.await
.expect_err;
assert!;
// Applying the already applied event, will be ignored and return Ok
account.record_that.await?;
// Balance hasn't changed since the event wasn't actually applied
assert_eq!;
println!;
Ok