[][src]Struct dgraph_tonic::ClientVariant

pub struct ClientVariant<S: IClient> { /* fields omitted */ }

Dgraph client has several variants which offer different behavior.

Implementations

impl ClientVariant<Default>[src]

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

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");

impl<C: IClient> ClientVariant<C>[src]

pub fn new_txn(&self) -> TxnType<C::Client>[src]

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

pub fn new_read_only_txn(&self) -> TxnReadOnlyType<C::Client>[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) -> TxnBestEffortType<C::Client>[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) -> TxnMutatedType<C::Client>[src]

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

pub async fn alter<'_>(&'_ self, op: Operation) -> Result<Payload, Error>[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};
#[cfg(feature = "acl")]
use dgraph_tonic::{AclClientType, LazyChannel};

#[cfg(not(feature = "acl"))]
async fn client() -> Client {
    Client::new("http://127.0.0.1:19080").expect("Dgraph client")
}

#[cfg(feature = "acl")]
async fn client() -> AclClientType<LazyChannel> {
    let default = Client::new("http://127.0.0.1:19080").unwrap();
    default.login("groot", "password").await.expect("Acl client")
}

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

pub async fn set_schema<'_, S: Into<String>>(
    &'_ self,
    schema: S
) -> Result<Payload, Error>
[src]

Create or change the schema.

Arguments

  • schema: Schema modification

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};
#[cfg(feature = "acl")]
use dgraph_tonic::{AclClientType, LazyChannel};

#[cfg(not(feature = "acl"))]
async fn client() -> Client {
    Client::new("http://127.0.0.1:19080").expect("Dgraph client")
}

#[cfg(feature = "acl")]
async fn client() -> AclClientType<LazyChannel> {
    let default = Client::new("http://127.0.0.1:19080").unwrap();
    default.login("groot", "password").await.expect("Acl client")
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = client().await;
    client.set_schema("name: string @index(exact) .").await.expect("Schema is not updated");
    Ok(())
}

pub async fn drop_all<'_>(&'_ self) -> Result<Payload, Error>[src]

Drop all data in DB

Errors

  • gRPC error
  • DB reject alter command

Example

use dgraph_tonic::{Client, Operation};
#[cfg(feature = "acl")]
use dgraph_tonic::{AclClientType, LazyChannel};

#[cfg(not(feature = "acl"))]
async fn client() -> Client {
    Client::new("http://127.0.0.1:19080").expect("Dgraph client")
}

#[cfg(feature = "acl")]
async fn client() -> AclClientType<LazyChannel> {
    let default = Client::new("http://127.0.0.1:19080").unwrap();
    default.login("groot", "password").await.expect("Acl client")
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = client().await;
    client.drop_all().await.expect("Data not dropped");
    Ok(())
}

pub async fn check_version<'_>(&'_ self) -> Result<Version, Error>[src]

Check DB version

Errors

  • gRPC error

Example

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"]).expect("Dgraph client");
    let version = client.check_version().await.expect("Version");
    println!("{:#?}", version);
    Ok(())
}

Methods from Deref<Target = Box<ClientState>>

Trait Implementations

impl<S: Debug + IClient> Debug for ClientVariant<S>[src]

impl<S: IClient> Deref for ClientVariant<S>[src]

type Target = Box<ClientState>

The resulting type after dereferencing.

impl<S: IClient> DerefMut for ClientVariant<S>[src]

Auto Trait Implementations

impl<S> RefUnwindSafe for ClientVariant<S> where
    S: RefUnwindSafe

impl<S> Send for ClientVariant<S>

impl<S> Sync for ClientVariant<S>

impl<S> Unpin for ClientVariant<S> where
    S: Unpin

impl<S> UnwindSafe for ClientVariant<S> where
    S: UnwindSafe

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, 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]