[][src]Struct dgraph_tonic::Client

pub struct Client { /* fields omitted */ }

Async client for dGraph DB.

Methods

impl Client[src]

pub async fn new<S: TryInto<Uri>>(endpoints: Vec<S>) -> Result<Self, Error>[src]

Create new dGraph client for interacting v DB and try to connect to given endpoints.

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

Arguments

  • endpoints - Vector of possible endpoints

Errors

  • connection to DB fails
  • endpoints vector is empty
  • item in vector cannot by converted into Uri

Example

use dgraph_tonic::Client;

#[tokio::main]
async fn main() {
    let client = Client::new(vec!["http://127.0.0.1:19080"]).await.expect("Connected to dGraph");
}

pub async fn new_with_tls_client_auth<S: TryInto<Uri>>(
    endpoints: Vec<S>,
    server_root_ca_cert: impl AsRef<Path>,
    client_cert: impl AsRef<Path>,
    client_key: impl AsRef<Path>
) -> Result<Self, Error>
[src]

Create new dGraph client authorized with SSL cert for interacting v DB and try to connect to given endpoints.

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

Arguments

  • endpoints - Vector of possible endpoints
  • server_root_ca_cert - path to server CA certificate
  • client_cert - path to client certificate
  • client_key - path to client private key

Errors

  • connection to DB fails
  • endpoints vector is empty
  • item in vector cannot by converted into Uri

pub fn new_txn(&self) -> Txn[src]

Return transaction in default state, which can be specialized into ReadOnly or Mutated

pub fn new_read_only_txn(&self) -> ReadOnlyTxn[src]

Create new transaction which can only do queries.

Read-only transactions are useful to increase read speed because they can circumvent the usual consensus protocol.

pub fn new_best_effort_txn(&self) -> BestEffortTxn[src]

Create new transaction which can only do queries in best effort mode.

Read-only queries can optionally be set as best-effort. Using this flag will ask the Dgraph Alpha to try to get timestamps from memory on a best-effort basis to reduce the number of outbound requests to Zero. This may yield improved latencies in read-bound workloads where linearizable reads are not strictly needed.

pub fn new_mutated_txn(&self) -> MutatedTxn[src]

Create new transaction which can do mutate, commit and discard operations

pub async fn alter<'_>(&'_ self, op: Operation) -> Result<Payload, Status>[src]

The /alter endpoint is used to create or change the schema.

Arguments

  • op: Alter operation

Errors

  • gRPC error
  • DB reject alter command

Example

Install a schema into dgraph. A name predicate is string type and has exact index.

use dgraph_tonic::{Client, Operation};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new(vec!["http://127.0.0.1:19080"]).await.expect("Connected to dGraph");
    let op = Operation {
        schema: "name: string @index(exact) .".into(),
        ..Default::default()
    };
    client.alter(op).await.expect("Schema is not updated");
    Ok(())
}

Trait Implementations

impl Clone for Client[src]

impl Debug for Client[src]

Auto Trait Implementations

impl !RefUnwindSafe for Client

impl Send for Client

impl Sync for Client

impl Unpin for Client

impl !UnwindSafe for Client

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoRequest<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> WithSubscriber for T[src]