https://github.com/foretaginc/arangodb-events-rs
Subscribe to real time events on your ArangoDB database in Rust
https://github.com/foretaginc/arangodb-events-rs
arangodb events triggers
Last synced: 7 days ago
JSON representation
Subscribe to real time events on your ArangoDB database in Rust
- Host: GitHub
- URL: https://github.com/foretaginc/arangodb-events-rs
- Owner: ForetagInc
- License: mpl-2.0
- Created: 2022-06-15T11:56:16.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-08-16T19:45:05.000Z (about 3 years ago)
- Last Synced: 2024-10-31T11:56:17.821Z (11 months ago)
- Topics: arangodb, events, triggers
- Language: Rust
- Homepage:
- Size: 59.6 KB
- Stars: 9
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ArangoDB Events
A library to add triggers to your ArangoDB database, when events occur (insert, update, delete etc.) on your
collections.[](https://crates.io/crates/arangodb_events_rs)


[](https://docs.rs/arangodb_events_rs/latest)## Documentation
- [API Documentation](https://docs.rs/arangodb_events_rs/)
## Features
- `async` Enables asynchronous `Handler::call` method## Installation
Add the crate to your `Cargo.toml`:
```toml
arangodb_events_rs = "0.1.6"
```## Usage
```rust
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::(
HandlerEvent::InsertOrReplace,
HandlerContextFactory::from(GlobalHandlerContext {
data: 10,
})
); // This subscribes for all Insert or Replace operations on the databasetrigger.subscribe_to::(
HandlerEvent::Remove,
"accounts",
HandlerContextFactory::from(AccountHandlerContext {
data: 50,
})
); // This is gonna listen only for Remove operations over accounts tabletrigger
.init()
.await
.expect("Error initializing ArangoDB Trigger");loop {
trigger
.listen()
.await
.expect("Error on Trigger listener loop");
}
}
```