Crates.io | arangodb_events_rs |
lib.rs | arangodb_events_rs |
version | 0.1.6 |
source | src |
created_at | 2022-08-12 08:54:46.269498 |
updated_at | 2022-08-16 19:51:19.545539 |
description | Subscribe to real time events on your ArangoDB database in Rust |
homepage | |
repository | https://github.com/ForetagInc/arangodb-events-rs |
max_upload_size | |
id | 643879 |
size | 58,490 |
A library to add triggers to your ArangoDB database, when events occur (insert, update, delete etc.) on your collections.
async
Enables asynchronous Handler::call
methodAdd the crate to your Cargo.toml
:
arangodb_events_rs = "0.1.6"
use arangodb_events_rs::api::DocumentOperation;
use arangodb_events_rs::{Handler, Trigger, HandlerContextFactory};
pub struct GlobalHandler;
pub struct GlobalHandlerContext {
pub data: u8,
}
impl Handler for GlobalHandler {
type Context = GlobalHandlerContext;
fn call(ctx: &GlobalHandlerContext, doc: &DocumentOperation) {
println!("{}", ctx.data); // 10
}
}
#[tokio::main]
async fn main() {
let mut trigger = Trigger::new_auth(
"http://localhost:8529/",
"database",
TriggerAuthentication::new("user", "password"),
);
trigger.subscribe::<GlobalHandler>(
HandlerEvent::InsertOrReplace,
HandlerContextFactory::from(GlobalHandlerContext {
data: 10,
})
); // This subscribes for all Insert or Replace operations on the database
trigger.subscribe_to::<AccountHandler>(
HandlerEvent::Remove,
"accounts",
HandlerContextFactory::from(AccountHandlerContext {
data: 50,
})
); // This is gonna listen only for Remove operations over accounts table
trigger
.init()
.await
.expect("Error initializing ArangoDB Trigger");
loop {
trigger
.listen()
.await
.expect("Error on Trigger listener loop");
}
}