[−][src]Struct dgraph_tonic::ClientVariant
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]
endpoints: E
) -> Result<Self, Error>
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]
&'_ self,
schema: S
) -> Result<Payload, Error>
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.
fn deref(&self) -> &Self::Target
[src]
impl<S: IClient> DerefMut for ClientVariant<S>
[src]
Auto Trait Implementations
impl<S> RefUnwindSafe for ClientVariant<S> where
S: RefUnwindSafe,
S: RefUnwindSafe,
impl<S> Send for ClientVariant<S>
impl<S> Sync for ClientVariant<S>
impl<S> Unpin for ClientVariant<S> where
S: Unpin,
S: Unpin,
impl<S> UnwindSafe for ClientVariant<S> where
S: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoRequest<T> for T
[src]
fn into_request(self) -> Request<T>
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<T> WithSubscriber for T
[src]
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]
S: Into<Dispatch>,