Minimal example?
Hi,
I just discovered eventually via the Reddit post today, and because I have never seen event sourcing in action I looked for an example. There is the example app, however, I think a more minimal one-file example would be useful for people who are interested in a quick overview.
Would that be possible, or is event sourcing too complex for a simple example like that?
++ Also how this library can be used with some database backend, for example, if I want to store all my events in PostgreSQL? In the current example, repository is in memory.
UPD: I think, a tutorial how to develop such app would be useful.
Hi @d4h0 and @AngelicosPhosphoros :wave:
Thank you for posting the issue!
@d4h0: it might be possible to put everything in a single file, however that file might be a tad long :sweat_smile: I'll try to make an easier example to follow. However, let me guide you through the current one.
As a good starting point, you can follow the aggregate module documentation, where you can see a minimal example of how to set up an Aggregate.
This is the main part of Event Sourcing from a user perspective, frankly.
Everything else is just wiring up the EventStore to the Repository and write the handlers that call the Repository and emits commands.
In eventually-app-example:
-
This is where you'll find the domain implementation, namely the
OrderAggregate -
This is where you call the
Repositoryto get anAggregateRootto submit commands (just an example of one single HTTP handler, there are more, one per each command) -
This is how you initialize
EventStoreandRepositoryin therun, then you can pass these objects to theStateof yourApp(if you're using Tide) so that they are accessible in the HTTP handlers (point 2.)
@AngelicosPhosphoros: indeed, the current example uses an inmemory EventStore.
I thought I included an example for setting up the Postgres' EventStore, but I'm afraid I forgot it.
You can find it in the crate documentation for eventually_postgres
I will include the documentation in the next patch release :+1:
Links are stale for this.