Client

Type Alias Client 

Source
pub type Client = ClientVariant<Http>;
Expand description

Default client.

Aliased Type§

pub struct Client { /* private fields */ }

Implementations§

Source§

impl Client

Source

pub fn new<S: TryInto<Uri>, E: Into<Endpoints<S>> + Debug>( endpoints: E, ) -> Result<Self>

Create new Dgraph client for interacting v DB.

The client can be backed by multiple endpoints (to the same server, or multiple servers in a cluster).

§Arguments
  • endpoints - one endpoint or vector of endpoints
§Errors
  • endpoints vector is empty
  • item in vector cannot by converted into Uri
§Example
use dgraph_tonic::Client;

// vector of endpoints
let client = Client::new(vec!["http://127.0.0.1:19080", "http://127.0.0.1:19080"]).expect("Dgraph client");
// one endpoint
let client = Client::new("http://127.0.0.1:19080").expect("Dgraph client");
Source

pub fn new_with_endpoint_config<S: TryInto<Uri>, E: Into<Endpoints<S>> + Debug, C: EndpointConfig + 'static>( endpoints: E, endpoint_config: C, ) -> Result<Self>

Create new Dgraph client with custom endpoint configuration for interacting with DB.

The client can be backed by multiple endpoints (to the same server, or multiple servers in a cluster).

§Arguments
  • endpoints - one endpoint or vector of endpoints
  • endpoint_config - custom endpoint configuration
§Errors
  • endpoints vector is empty
  • item in vector cannot by converted into Uri
§Example
use dgraph_tonic::{Endpoint, EndpointConfig, Client};

use std::time::Duration;

#[derive(Debug, Default, Clone)]
struct EndpointWithTimeout {}

impl EndpointConfig for EndpointWithTimeout {
    fn configure_endpoint(&self, endpoint: Endpoint) -> Endpoint {
        endpoint.timeout(Duration::from_secs(5))
    }
}

// custom configuration
let endpoint_config = EndpointWithTimeout::default();
// vector of endpoints
let client = Client::new_with_endpoint_config(vec!["http://127.0.0.1:19080", "http://127.0.0.1:19080"], endpoint_config.clone()).expect("Dgraph client");
// one endpoint
let client = Client::new_with_endpoint_config("http://127.0.0.1:19080", endpoint_config).expect("Dgraph client");