better inline docs

main
Ziyang Hu 2 years ago
parent 3c83761ec6
commit 359b58246c

@ -377,20 +377,20 @@ impl DbInstance {
}
/// Dispatcher method. See [crate::Db::register_callback].
#[cfg(not(target_arch = "wasm32"))]
pub fn register_callback<CB>(&self, callback: CB, dependent: &str) -> Result<u32>
pub fn register_callback<CB>(&self, relation: &str, callback: CB) -> Result<u32>
where
CB: Fn(CallbackOp, NamedRows, NamedRows) + Send + Sync + 'static,
{
match self {
DbInstance::Mem(db) => db.register_callback(callback, dependent),
DbInstance::Mem(db) => db.register_callback(relation, callback),
#[cfg(feature = "storage-sqlite")]
DbInstance::Sqlite(db) => db.register_callback(callback, dependent),
DbInstance::Sqlite(db) => db.register_callback(relation, callback),
#[cfg(feature = "storage-rocksdb")]
DbInstance::RocksDb(db) => db.register_callback(callback, dependent),
DbInstance::RocksDb(db) => db.register_callback(relation, callback),
#[cfg(feature = "storage-sled")]
DbInstance::Sled(db) => db.register_callback(callback, dependent),
DbInstance::Sled(db) => db.register_callback(relation, callback),
#[cfg(feature = "storage-tikv")]
DbInstance::TiKv(db) => db.register_callback(callback, dependent),
DbInstance::TiKv(db) => db.register_callback(relation, callback),
}
}

@ -536,7 +536,7 @@ impl<'s, S: Storage<'s>> Db<S> {
}
}
/// Register callbacks to run when changes to relations are committed.
/// Register callbacks to run when changes to the requested relation are successfully committed.
/// The returned ID can be used to unregister the callbacks.
///
/// When any mutation is made against the registered relation,
@ -550,19 +550,16 @@ impl<'s, S: Storage<'s>> Db<S> {
/// * For `Put`, old rows that were updated
/// * For `Rm`, the rows actually removed.
///
/// Callbacks are called after mutations have been committed.
/// Failed transactions do not trigger callbacks.
///
/// The database has a single dedicated thread for executing callbacks no matter how many callbacks
/// are registered. You should not perform blocking operations in the callback provided to this function.
/// If blocking operations are required, send the data to some other thread and perform the operations there.
#[cfg(not(target_arch = "wasm32"))]
pub fn register_callback<CB>(&self, callback: CB, dependent: &str) -> Result<u32>
pub fn register_callback<CB>(&self, relation: &str, callback: CB) -> Result<u32>
where
CB: Fn(CallbackOp, NamedRows, NamedRows) + Send + Sync + 'static,
{
let cb = CallbackDeclaration {
dependent: SmartString::from(dependent),
dependent: SmartString::from(relation),
callback: Box::new(callback),
};
@ -570,7 +567,7 @@ impl<'s, S: Storage<'s>> Db<S> {
let new_id = self.callback_count.fetch_add(1, Ordering::SeqCst);
guard
.1
.entry(SmartString::from(dependent))
.entry(SmartString::from(relation))
.or_default()
.insert(new_id);

@ -21,9 +21,9 @@ use crate::data::symb::Symbol;
use crate::data::value::DataValue;
use crate::fixed_rule::FixedRulePayload;
use crate::parse::SourceSpan;
use crate::{new_cozo_mem, FixedRule, RegularTempStore};
use crate::runtime::callback::CallbackOp;
use crate::runtime::db::Poison;
use crate::{new_cozo_mem, FixedRule, RegularTempStore};
#[test]
fn test_limit_offset() {
@ -446,10 +446,9 @@ fn test_callback() {
let db = new_cozo_mem().unwrap();
let collected = Arc::new(Mutex::new(vec![]));
let copy = collected.clone();
db.register_callback(
move |op, new, old| copy.lock().unwrap().push((op, new, old)),
"friends",
)
db.register_callback("friends", move |op, new, old| {
copy.lock().unwrap().push((op, new, old))
})
.unwrap();
db.run_script(
":create friends {fr: Int, to: Int => data: Any}",

Loading…
Cancel
Save