pub struct GenericConnection<C: ClientExt, S = Normal> { /* private fields */ }
Expand description

Connection is the top level API for this crate. It contains a http client, information about authentication, arangodb url.

Implementations§

source§

impl<S, C: ClientExt> GenericConnection<C, S>

source

pub async fn validate_server(arango_url: &str) -> Result<(), ClientError>

Validate the server at given arango url

Cast ClientError if

  • Invalid url
  • Connection failed
  • SERVER header in response header is not ArangoDB or empty
source

pub fn url(&self) -> &Url

Get url for remote arangoDB server.

source

pub fn session(&self) -> Arc<C>

Get HTTP session.

Users can use this method to get a authorized session to access arbitrary path on arangoDB Server.

TODO This method should only be public in this crate when all features are implemented.

source

pub async fn db(&self, name: &str) -> Result<Database<C>, ClientError>

Get database object with name.

Note

this function would make a request to arango server.

source

pub async fn accessible_databases( &self ) -> Result<HashMap<String, Permission>, ClientError>

Get a list of accessible database

This function uses the API that is used to retrieve a list of all databases the current user can access.

Note

this function would make a request to arango server.

source

pub async fn server_role(&self) -> Result<String, ClientError>

Possible return values for role are: SINGLE: the server is a standalone server without clustering COORDINATOR: the server is a Coordinator in a cluster PRIMARY: the server is a DB-Server in a cluster SECONDARY: this role is not used anymore AGENT: the server is an Agency node in a cluster UNDEFINED: in a cluster, UNDEFINED is returned if the server role cannot be determined.

Note

this function would make a request to arango server.

source§

impl<C: ClientExt> GenericConnection<C, Normal>

source

pub async fn establish_without_auth<T: Into<String>>( arango_url: T ) -> Result<GenericConnection<C, Normal>, ClientError>

Establish connection to ArangoDB sever without Authentication.

The target server MUST DISABLE authentication for all requests, which should only used for test purpose.

Disable authentication means all operations are performed by root user.

Example:

use arangors::Connection;

let conn = Connection::establish_without_auth("http://localhost:8529").await.unwrap();
source

pub async fn establish_basic_auth( arango_url: &str, username: &str, password: &str ) -> Result<GenericConnection<C, Normal>, ClientError>

Establish connection to ArangoDB sever with basic auth.

Example:

use arangors::Connection;

let conn = Connection::establish_basic_auth("http://localhost:8529", "username", "password")
    .await
    .unwrap();
source

pub async fn establish_jwt( arango_url: &str, username: &str, password: &str ) -> Result<GenericConnection<C, Normal>, ClientError>

Establish connection to ArangoDB sever with jwt authentication.

Prefered way to interact with arangoDB server.

JWT token expires after 1 month.

Example:

use arangors::Connection;

let conn = Connection::establish_jwt("http://localhost:8529", "username", "password")
    .await
    .unwrap();
source

pub async fn create_database( &self, name: &str ) -> Result<Database<C>, ClientError>

Create a database via HTTP request and add it into self.databases.

If creation fails, an Error is cast. Otherwise, a bool is returned to indicate whether the database is correctly created.

Example
use arangors::Connection;
let conn = Connection::establish_jwt("http://localhost:8529", "root", "KWNngteTps7XjrNv")
    .await
    .unwrap();
let result = conn.create_database("new_db").await.unwrap();
println!("{:?}", result);

let result = conn.drop_database("new_db").await.unwrap();
println!("{:?}", result);

TODO tweak options on creating database

Note

this function would make a request to arango server.

source

pub async fn drop_database(&self, name: &str) -> Result<(), ClientError>

Drop database with name.

Note

this function would make a request to arango server.

source

pub async fn into_admin( self ) -> Result<GenericConnection<C, Admin>, ClientError>

source§

impl<C: ClientExt> GenericConnection<C, Admin>

Trait Implementations§

source§

impl<C: Clone + ClientExt, S: Clone> Clone for GenericConnection<C, S>

source§

fn clone(&self) -> GenericConnection<C, S>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<C: Debug + ClientExt, S: Debug> Debug for GenericConnection<C, S>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<C: ClientExt> From<GenericConnection<C, Admin>> for GenericConnection<C, Normal>

source§

fn from(conn: GenericConnection<C, Admin>) -> GenericConnection<C, Normal>

Converts to this type from the input type.
source§

impl<C: ClientExt> From<GenericConnection<C, Normal>> for GenericConnection<C, Admin>

source§

fn from(conn: GenericConnection<C, Normal>) -> GenericConnection<C, Admin>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<C, S> RefUnwindSafe for GenericConnection<C, S>where C: RefUnwindSafe, S: RefUnwindSafe,

§

impl<C, S> Send for GenericConnection<C, S>where C: Send, S: Send,

§

impl<C, S> Sync for GenericConnection<C, S>where C: Send, S: Sync,

§

impl<C, S> Unpin for GenericConnection<C, S>where S: Unpin,

§

impl<C, S> UnwindSafe for GenericConnection<C, S>where C: RefUnwindSafe, S: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more