Struct dittolive_ditto::store::query_builder::LiveQuery
source · pub struct LiveQuery {
pub query: Box,
pub collection_name: Box,
pub subscription: Option<Box<Subscription>>,
pub id: i64,
/* private fields */
}
Expand description
Use .observe_local(...)
to create a LiveQuery
with a callback that fires when
any queried documents are changed in the local store.
The LiveQuery
object itself is a handle that keeps the registered callback alive.
Dropping a LiveQuery
will cancel any future calls to the callback, so be sure to
keep it in scope for as long as you wish to continue receiving updates.
§Example
// Hold the LiveQuery to keep the callback alive
let _live_query =
ditto
.store()
.collection("cars")?
.find_all()
.observe_local(|docs, _event| {
let typed_docs: Vec<serde_json::Value> = docs
.into_iter()
.flat_map(|doc| doc.typed::<serde_json::Value>().ok())
.collect();
println!("Received doc updates: {typed_docs:?}");
})?;
// Drop the LiveQuery to cancel the callback
drop(_live_query);
Fields§
§query: Box
§collection_name: Box
§subscription: Option<Box<Subscription>>
§id: i64
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LiveQuery
impl RefUnwindSafe for LiveQuery
impl Send for LiveQuery
impl Sync for LiveQuery
impl Unpin for LiveQuery
impl UnwindSafe for LiveQuery
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
Mutably borrows from an owned value. Read more