disintegrate-es / disintegrate

Disintegrate Rust library
https://disintegrate-es.github.io/disintegrate/
MIT License
48 stars 4 forks source link

Querying via event store #120

Open dspasojevic opened 1 month ago

dspasojevic commented 1 month ago

Thanks for writing this library, I really like the look of it.

I am doing a proof-of-concept of using this library to manage state for turn-based games. When a client joins, I'd like to be able to send them a list of all events that have been persisted for a particular game.

In the courses example, querying seems to be implemented by going to the database directly rather than via the event store.

Do you have any plans to support querying events by domain entity via the event store so that the details of the event store implementation are abstracted?

luca-iachini commented 1 month ago

Hi @dspasojevic,

Thank you for your feedback! Could you please provide more context on what you're trying to achieve? This will help us better understand if there's room for improvement in our API.

To access events through the event store, you can use the stream method of the EventStore. You can query EventStore like this:

event_store.stream(&query!(GameEvents, game_id == game_id)).await;

Or, if you're retrieving events from the last_seen_event_id:

event_store.stream(&query!(last_seen_event_id; GameEvents, game_id == game_id)).await;

Let us know if this answer your question.