Crate faunadb

Source
Expand description

§FaunaDB

faunadb is a client for the Fauna database in Rust. It provides the query and expression types, (de-)serialization and an asynchronous client.

Additionally the crate holds a SyncClient wrapper for synchronous execution, enabled with the sync_client feature flag.

Most of the type checks are handled in Fauna and the functions accept anything that can be converted to the Expr enum, allowing the usage of different Fauna types in a more dynamic manner.

§Asynchronous example:

use futures::{future::lazy, Future};
use faunadb::prelude::*;

fn main() {
    let client = Client::builder("my_fauna_secret").build().unwrap();

    let query = Filter::new(
        Lambda::new("x", Gt::new(Var::new("x"), 2)),
        Array::from(vec![1, 2, 3]),
    );

    tokio::run(lazy(move || {
        client
            .query(query)
            .map(|response| {
                println!("{:#?}", response);
            })
            .map_err(|error: faunadb::error::Error| {
                println!("Error: {:#?}", error);
            })
    }));
}

§Synchronous example:

use faunadb::prelude::*;

fn main() {
    let mut client = Client::builder("my_fauna_secret").build_sync().unwrap();

    let query = Filter::new(
        Lambda::new("x", Gt::new(Var::new("x"), 2)),
        Array::from(vec![1, 2, 3]),
    );

    match client.query(query) {
        Ok(response) => println!("{:#?}", response),
        Err(error) => println!("Error: {:#?}", error),
    }
}

Modules§

  • Tools for communicating with Fauna.
  • A Fauna expression that is either a value or a function that evaluates to a value.
  • A special case of an expression that needs to be evaluated to a value.

Macros§

  • A helper macro to implement From trait from the given query type into the Query enum, boxing the query.
  • A convenience to convert a type of a signed integer into Fauna Expr.
  • A helper macro to implement From trait from the given query type into the Query enum.
  • A convenience to convert a type of a unsigned integer into Fauna Expr.

Type Aliases§