2 releases

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

#2316 in Database interfaces

Download history 191/week @ 2024-01-01 149/week @ 2024-01-08 145/week @ 2024-01-15 83/week @ 2024-01-22 221/week @ 2024-01-29 643/week @ 2024-02-05 145/week @ 2024-02-12 152/week @ 2024-02-19 215/week @ 2024-02-26 179/week @ 2024-03-04 193/week @ 2024-03-11 173/week @ 2024-03-18 142/week @ 2024-03-25 160/week @ 2024-04-01 198/week @ 2024-04-08 135/week @ 2024-04-15

663 downloads per month

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

~13–28MB
~417K SLoC