1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
use_prelude!();
use super::*;
#[derive(Debug)]
/// Describes the different types of event that you can receive when dealing with live queries.
pub enum LiveQueryEvent {
/// The first event that will be delivered and it will only be delivered once.
Initial,
/// This event will be delivered each time the results of the provided query change. It
/// contains information about the set of documents that previously matched the query
/// before the update, along with information about what documents have been inserted,
/// deleted, updated, or moved, as part of the set of matching documents.
Update {
old_documents: Vec<ffi_sdk::BoxedDocument>,
insertions: Box<[usize]>,
deletions: Box<[usize]>,
updates: Box<[usize]>,
moves: Vec<LiveQueryMove>,
},
}
impl LiveQueryEvent {
/// Return an hash of a document
pub fn hash(&self, docs: &[ffi_sdk::BoxedDocument]) -> Result<u64, DittoError> {
ffi_sdk::ditto_documents_hash(docs.into()).ok()
}
/// Return the hash the `Document`s mnemonic.
pub fn hash_mnemonic(&self, docs: &[ffi_sdk::BoxedDocument]) -> Result<String, DittoError> {
let mnemonic_c_str = { ffi_sdk::ditto_documents_hash_mnemonic(docs.into()).ok()? };
Ok(mnemonic_c_str.into_string())
}
}