Crate ruarango[−][src]
Expand description
ruarango
A database driver written in Rust for the ArangoDB
database.
While the API for ruarango
is async, ArangoDB
supports 3 modes of operation. They are blocking, store, and fire & forget.
The latter two modes are asynchronus, while the first is synchronous. More details can be found
here. See below for examples of using
the driver in these various modes.
Synchronous Blocking Connection
Use the driver in Blocking
mode
// Use `ConnectionBuilder` to build a connection and pull in the // traits for operations you wish to use use ruarango::{ConnectionBuilder, Database}; // Setup a synchronous connection to the database let conn = ConnectionBuilder::default() .url(url) // The normal url for ArangoDB running locally is http://localhost:8529 .username("root") .password("") .database("test_db") .build() .await?; // Use the connection to query information about the current database let res = conn.current().await?; // Get the sync results out of the right side of the `Either` assert!(res.is_right()); let contents = res.right_safe()?; assert!(!contents.error()); assert_eq!(*contents.code(), 200); assert_eq!(contents.result().name(), "test"); assert_eq!(contents.result().id(), "123"); assert!(!contents.result().is_system());
Asynchronous Store Connection
Use the driver in Store
mode
// Use `ConnectionBuilder` to build a connection and pull in the // traits for operations you wish to use use ruarango::{ConnectionBuilder, Database, Job}; // Setup a asynchronous store connection to the database let conn = ConnectionBuilder::default() .url(url) // The normal url for ArangoDB running locally is http://localhost:8529 .username("root") .password("") .database("test_db") .async_kind(AsyncKind::Store) .build() .await?; // Use the connection to spawn a job for information about the current database // This will return immediately with a 202 code and job information if the job // was accepted into the queue. let res = conn.current().await?; // Get the async job info results out of the left side of the `Either` assert!(res.is_left()); let contents = res.left_safe()?; assert_eq!(*contents.code(), 202); assert!(contents.id().is_some()); let job_id = contents.id().as_ref().ok_or_else(|| anyhow!("invalid job_id"))?; assert_eq!(job_id, "123456"); // Check status until we get 200 (or error out on 404) let mut status = conn.status(job_id).await?; assert!(status == 200 || status == 204); while status != 200 { std::thread::sleep(std::time::Duration::from_millis(500)); status = conn.status(job_id).await?; } // Fetch the results (this has the side effect of removing the job off of the server) let res: Response<Current> = conn.fetch(job_id).await?; assert!(!res.error()); assert_eq!(*res.code(), 200); assert_eq!(res.result().name(), "test"); assert_eq!(res.result().id(), "123"); assert!(!res.result().is_system());
Asynchronous Fire & Forget Connection
Use the driver in Fire & Forget
mode
// Use `ConnectionBuilder` to build a connection and pull in the // traits for operations you wish to use use ruarango::{ConnectionBuilder, Database, Job}; // Setup a asynchronous store connection to the database let conn = ConnectionBuilder::default() .url(url) // The normal url for ArangoDB running locally is http://localhost:8529 .username("root") .password("") .database("test_db") .async_kind(AsyncKind::FireAndForget) .build() .await?; // Use the connection to spawn a job for information about the current database // In this case, fire and forget isn't useful, but for other operations it // may be. Fire and Forget jobs run on the server and do not store results. let res = conn.current().await?; // Check that the job was accepted into the queue. assert!(res.is_left()); let contents = res.left_safe()?; assert_eq!(*contents.code(), 202); assert!(contents.id().is_none());
Modules
coll |
|
common | |
cursor | |
db | |
doc | |
graph |
Structs
Connection | An |
ConnectionBuilder | Builder for |
JobInfo | Job Information from an asynchronous invocation |
Enums
AsyncKind | The kind of asynchronouse request you would like to make |
Error | When bad things happen |
Traits
Collection | Collection Operations |
Cursor | Cursor Operations |
Database | Database Operations |
Document | Document Operations |
Graph | Database Operations |
Job | Collection Operations |
Type Definitions
ArangoEither | Either |
ArangoResult | A result that on success is either |
ArangoVec | |
ArangoVecResult | |
DocMetaResult | An |
DocMetaVecResult |