9 releases (5 breaking)

0.6.0 May 22, 2021
0.5.1 Jun 22, 2020
0.4.0 Apr 12, 2020
0.3.1 Apr 8, 2020
0.1.0 Aug 1, 2019

#2714 in Database interfaces

Download history 9/week @ 2024-07-16 38/week @ 2024-07-30 14/week @ 2024-08-06 5/week @ 2024-08-20 15/week @ 2024-08-27 16/week @ 2024-09-03 1/week @ 2024-09-10 9/week @ 2024-09-17 25/week @ 2024-09-24 15/week @ 2024-10-01 28/week @ 2024-10-08 21/week @ 2024-10-15 5/week @ 2024-10-22 10/week @ 2024-10-29

64 downloads per month
Used in testcontainers-avk

Apache-2.0

160KB
5K SLoC

orientdb-rs

Build Status Codecov Status Crates.io Crates.io Download License Docs dependency status Codacy Badge

OrientDB Client

A Rust Client for OrientDB. Supports sync and async (tokio and async-std)

Installation

Install from crates.io

[dependencies]
orientdb-client = "*"

Cargo Features

  • async-std-runtime: use the async APIs with async-std.
  • tokio-runtime: use the async APIs with tokio.
  • uuid: Add support for UUID.
  • sugar: Add ergonimic APIs for querying and binding results to structs

Example

Basic Usage Synchronous


use orientdb_client::{OrientDB};

fn main() -> Result<(), Box<std::error::Error>> {
    let client = OrientDB::connect(("localhost",2424))?;

    let session = client.session("demodb","admin","admin")?;

    let results : Vec<_> = session.query("select from V where id = :param").named(&[("param", &1)]).run()?.collect();


    println!("{:?}", results);

    Ok(())
}

Basic Usage Asynchronous

For async-std

activate the feature async-std-runtime

orientdb-client = { version = "*", features = ["async-std-runtime"] }

use async_std::task::block_on;
use futures::StreamExt;
use orientdb_client::aio::OrientDB;
use orientdb_client::OrientResult;

fn main() -> OrientResult<()> {
    block_on(async {
        let client = OrientDB::connect(("localhost", 2424)).await?;

        let session = client.session("demodb", "admin", "admin").await?;

        let mut stream = session.query("select from V limit 10").run().await?;

        while let Some(item) = stream.next().await {
            println!("Record {:?}", item?);
        }

        Ok(())
    })
}

For tokio

activate the feature tokio-runtime

orientdb-client = { version = "*", features = ["tokio-runtime"] }

use futures::StreamExt;
use orientdb_client::aio::OrientDB;
use orientdb_client::OrientResult;

#[tokio::main]
async fn main() -> OrientResult<()> {
    let client = OrientDB::connect(("localhost", 2424)).await?;

    let session = client.session("demodb", "admin", "admin").await?;

    let mut stream = session.query("select from V limit 10").run().await?;

    while let Some(item) = stream.next().await {
        println!("Record {:?}", item?);
    }

    Ok(())
}

Additional Features

sugar feature

The sugar feature add 3 methods to the query builder for spawning the query.

  • fetch_one
  • fetch
  • stream for async or iter for sync

They should be used instead of run APIs when you want to execute the query and map the OResult into a struct.

The sugar is supported in sync and async mode.

fetch_one

Consume the stream and fetch the first result if any.

use orientdb_client::derive::FromResult;
#[derive(FromResult, Debug)]
struct User {
    name: String,
}

// fetch one
let user: Option<User> = session
    .query("select from OUser limit 1")
    .fetch_one()
    .await?;

println!("User {:?}", user);`

fetch

Collect the stream to a Vec and map to struct.

use orientdb_client::derive::FromResult;
#[derive(FromResult, Debug)]
struct User {
    name: String,
}

// fetch 
let user: Vec<User> = session
    .query("select from OUser limit 1")
    .fetch()
    .await?;

println!("Users {:?}", user);`

stream

Map each item of the stream to a struct.

use orientdb_client::derive::FromResult;
#[derive(FromResult, Debug)]
struct User {
    name: String,
}

// fetch stream and collect
let stream = session
            .query("select from OUser")
            .stream::<User>()
            .await?
            .collect::<Vec<_>>()
            .await;
println!("Users {:?}", user);

Development

Compiling

git clone https://github.com/wolf4ood/orientdb-rs.git
cd orientdb-rs
cargo build

Running Tests

You can use docker-compose to start an instance for testing. Use the env variable ORIENTDB_SERVER in order to specify the version of OrientDB

cd docker-compose
export ORIENTDB_SERVER=3.0.23
docker-compose up -d
cd ..
cargo test

Dependencies

~4–15MB
~204K SLoC