2 releases

0.1.2 Jan 14, 2023
0.1.1 Jan 14, 2023
0.1.0 May 12, 2021

#2708 in Database interfaces

Download history 149/week @ 2024-07-19 164/week @ 2024-07-26 202/week @ 2024-08-02 188/week @ 2024-08-09 136/week @ 2024-08-16 146/week @ 2024-08-23 106/week @ 2024-08-30 104/week @ 2024-09-06 116/week @ 2024-09-13 130/week @ 2024-09-20 150/week @ 2024-09-27 160/week @ 2024-10-04 163/week @ 2024-10-11 185/week @ 2024-10-18 142/week @ 2024-10-25 177/week @ 2024-11-01

687 downloads per month
Used in bb8-ruarango

MIT/Apache

350KB
7.5K SLoC

ruarango


lib.rs:

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());

Dependencies

~14–27MB
~396K SLoC