pub struct Store { /* private fields */ }Expand description
A listener’s store: JSON values under keys, grouped in namespaces (ns), in a SQLite file or
in memory; see crate::Listener::store. Cloning gives another handle to it. Handlers get
it as ctx.store: if let Some(store) = &ctx.store { store.set("carts", &evt.aggregate_id, &row)?; }. What an event handler writes takes effect together with the listener’s
position, once per batch. Errors are Error::Store (SQLite) or Error::Json.
Implementations§
Source§impl Store
impl Store
Sourcepub fn open(url: &str, schema: &str) -> Result<Store, Error>
pub fn open(url: &str, schema: &str) -> Result<Store, Error>
Opens url (sqlite:<path>, a bare path, or memory:). If the stored data was built
at another schema, it is cleared and the read model rebuilds from the first event.
Sourcepub fn committed_for(&self, part: &str) -> Result<u64, Error>
pub fn committed_for(&self, part: &str) -> Result<u64, Error>
The position up to which the data is complete for the events of partition part: every
partition has its own positions. "": a kernel without partitions.
Sourcepub fn get<T: DeserializeOwned>(
&self,
ns: &str,
key: &str,
) -> Result<Option<T>, Error>
pub fn get<T: DeserializeOwned>( &self, ns: &str, key: &str, ) -> Result<Option<T>, Error>
The value under key in namespace ns as a T; None if there is none.
Sourcepub fn set<T: Serialize + ?Sized>(
&self,
ns: &str,
key: &str,
value: &T,
) -> Result<(), Error>
pub fn set<T: Serialize + ?Sized>( &self, ns: &str, key: &str, value: &T, ) -> Result<(), Error>
Stores value as JSON under key in namespace ns, replacing a value there.
Sourcepub fn remove(&self, ns: &str, key: &str) -> Result<(), Error>
pub fn remove(&self, ns: &str, key: &str) -> Result<(), Error>
Removes the value under key in namespace ns, if there is one.
Sourcepub fn all<T: DeserializeOwned>(
&self,
ns: &str,
) -> Result<Vec<(String, T)>, Error>
pub fn all<T: DeserializeOwned>( &self, ns: &str, ) -> Result<Vec<(String, T)>, Error>
Every key and value of a namespace, ordered by key.
Sourcepub fn close(&self)
pub fn close(&self)
Closes the store for every handle to it: a batch still open is dropped, the
write-ahead log emptied into the file (so data removed is gone from disk too), and the
file released. Using it afterwards is an Error::Store. A listener closes its store
when its run() ends; a later run opens it again.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Store
impl !UnwindSafe for Store
impl Forget for Store
impl Freeze for Storewhere
*const ArcInner<Mutex<Option<Connection>>> is !null: Freeze,
PhantomData<ArcInner<Mutex<Option<Connection>>>>: Freeze,
*const ArcInner<Atomic<u64>> is !null: Freeze,
PhantomData<ArcInner<Atomic<u64>>>: Freeze,
*const ArcInner<Mutex<()>> is !null: Freeze,
PhantomData<ArcInner<Mutex<()>>>: Freeze,
impl Move for Store
impl Send for Store
impl Sync for Store
impl Unpin for Store
impl UnsafeUnpin for Storewhere
*const ArcInner<Mutex<Option<Connection>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<Option<Connection>>>>: UnsafeUnpin,
*const ArcInner<Atomic<u64>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Atomic<u64>>>: UnsafeUnpin,
*const ArcInner<Mutex<()>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<()>>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request