[][src]Struct eventually_postgres::EventStoreBuilder

pub struct EventStoreBuilder(_);

Builder type for EventStore instances.

Implementations

impl EventStoreBuilder[src]

pub fn event_stream<Id, Event>(
    &self,
    name: &'static str
) -> EventStore<Id, Event>
[src]

Creates a new EventStore instance using the specified stream name as the Postgres backend table.

pub fn aggregate_stream<T>(
    &self,
    _: &T,
    name: &'static str
) -> EventStore<AggregateId<T>, T::Event> where
    T: Aggregate, 
[src]

Creates a new EventStore for an Aggregate type, backed by a Postgres table using the specified stream name.

Usage

// Open a connection with Postgres.
let (client, connection) =
    tokio_postgres::connect("postgres://user@pass:localhost:5432/db", tokio_postgres::NoTls)
        .await
        .map_err(|err| {
            eprintln!("failed to connect to Postgres: {}", err);
            err
        })?;

// The connection, responsible for the actual IO, must be handled by a different
// execution context.
tokio::spawn(async move {
    if let Err(e) = connection.await {
        eprintln!("connection error: {}", e);
    }
});

// Use an EventStoreBuilder to build multiple EventStore instances.
let builder = EventStoreBuilder::from(Arc::new(RwLock::new(client)));

// Aggregates should be versioned to be used with the Postgres Event Store.
use eventually_util::versioned::AggregateExt;
let aggregate = SomeAggregate.versioned();

// Event store for the events.
let store = {
    let store = builder.aggregate_stream(&aggregate, "orders");
    store.create_stream().await?;
    store
};

Trait Implementations

impl From<Arc<RwLock<Client>>> for EventStoreBuilder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,