Crate rincon_session [−] [src]
Synchronous Session API
The synchronous session API is the most convenient way to use this driver.
It is provided by the rincon_session crate.
Here is some example code to showcase the basic usage of the session API:
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] struct Person { name: String, age: u16, } let person = Person { name: "herbert".to_string(), age: 42 }; let friendsbook = session.use_database_with_name("friendsbook"); let people = friendsbook.create_collection("people")?; let doc_header = people.insert_document(person)?; let (_, doc_key, _) = doc_header.deconstruct(); let document: Document<Person> = people.get_document(doc_key)?;
If you have a closer look at this example you may ask what this session is
that we are accessing in the second let statement. This is an
ArangoSession instance from the rincon_session API. Lets create such
an ArangoSession instance step by step.
To use the rincon_session API add this to your Cargo.toml:
[dependencies]
rincon_core = "0.1"
rincon_session = "0.1"
rincon_connector = "0.1"
tokio-core = "0.1"
And in your crate root add this:
extern crate rincon_core; extern crate rincon_connector; extern crate rincon_session; extern crate tokio_core;
The tokio_core crate is needed for instantiating a Connector as we will
see in a moment.
First we configure a DataSource for our ArangoDB server. A DataSource
is a struct that holds the parameters needed to connect to a concrete
installation of ArangoDB.
use rincon_core::api::datasource::DataSource; use std::str::FromStr; fn main() { let datasource = DataSource::from_str("http://localhost:8529") .expect("invalid URL for datasource") .with_basic_authentication("root", "s3cur3"); }
Next we create a Connector which will be used to communicate with the
ArangoDB server. The Connector defines which transport protocol is used
and how the payload is serialized. We choose the provided
JsonHttpConnector which support HTTP and HTTPS and serializes the payload
as JSON.
use rincon_core::api::datasource::DataSource; use rincon_connector::http::JsonHttpConnector; use tokio_core::reactor::Core; use std::str::FromStr; fn main() { let datasource = DataSource::from_str("http://localhost:8529") .expect("invalid URL for datasource") .with_basic_authentication("root", "s3cur3"); let mut core = Core::new().unwrap(); let connector = JsonHttpConnector::new(datasource, &core.handle()).unwrap(); }
The new() method of the JsonHttpConnector takes 2 arguments. The first
argument is the datasource we have just created before. The second argument
is a handle to reactor::Core from the tokio_core crate.
And finally we create an ArangoSession:
use rincon_core::api::datasource::DataSource; use rincon_connector::http::JsonHttpConnector; use rincon_session::ArangoSession; use tokio_core::reactor::Core; use std::str::FromStr; fn main() { let datasource = DataSource::from_str("http://localhost:8529") .expect("invalid URL for datasource") .with_basic_authentication("root", "s3cur3"); let mut core = Core::new().unwrap(); let connector = JsonHttpConnector::new(datasource, &core.handle()).unwrap(); let session = ArangoSession::new(connector, core); }
Now we are ready to conveniently interact with the ArangoDB server as shown in the example at the beginning of this chapter.
Modules
| client |
Re-export of types from the |
Structs
| ArangoSession |
A session for administrating databases and users. |
| CollectionSession |
A session for operating with a specific collection. |
| CursorSession |
A session for operating with a specific |
| CursorSessionIntoIter |
An |
| DatabaseSession |
A session for operating with a specific database. |
| EdgeCollectionSession |
A session for operating with a specific edge collection. |
| GraphSession |
A session for operating with a specific graph. |
| VertexCollectionSession |
A session for operating with a specific vertex collection. |
Type Definitions
| Result |
The |