[][src]Struct couchbase::Cluster

pub struct Cluster { /* fields omitted */ }

The Cluster is the main entry point when working with the client.

Methods

impl Cluster[src]

pub fn connect<S>(
    connection_string: S,
    username: S,
    password: S
) -> Result<Self, CouchbaseError> where
    S: Into<String>, 
[src]

Creates a new connection reference to the Couchbase cluster.

Keep in mind that only Role-Based access control (RBAC) is supported, so you need to configure a username and password on the cluster. This implies that only Couchbase Server versions 5.0 and later are supported.

Arguments

  • connection_string - Holds the bootstrap hostnames and optionally config settings.
  • username - The name of the user configured on the cluster.
  • password - The password of the user configured on the cluster.

Examples

use couchbase::Cluster;

let mut cluster = Cluster::connect("couchbase://127.0.0.1", "Administrator", "password")
  .expect("Could not create cluster reference");

pub fn bucket<S>(&mut self, name: S) -> Result<Rc<Bucket>, CouchbaseError> where
    S: Into<String>, 
[src]

Opens a Couchbase bucket.

If you wonder why this returns an Rc, the reason is that we also need to keep track of the Bucket internally so if you call disconnect on the Cluster all opened buckets are closed. Also, we make sure that if this method is called more than once on the same bucket, it is only opened once since buckets are expensive resources with state attached (for those familiar with libcouchbase: the bucket internally holds the lcb instance).

We recommend only ever opening a bucket once and then reusing it across the lifetime of your application for maximum performance and resource efficiency.

Arguments

  • name - The name of the bucket.

Examples

let bucket = cluster.bucket("travel-sample")
    .expect("Could not open bucket");

pub fn query<S>(
    &self,
    statement: S,
    options: Option<QueryOptions>
) -> impl Future<Item = QueryResult, Error = CouchbaseError> where
    S: Into<String>, 
[src]

Performs a query against the N1QL query service.

For now, please make sure to open one bucket (doesn't matter which one) before performing a cluster-level query. This limiation will be lifted in the future, but for now the client needs an open bucket so it knows where internally to route the query.

Arguments

  • statement - The query string itself.
  • options - Options to customize the default behavior.

Examples

use couchbase::{CouchbaseError, Cluster};
use futures::{Stream, Future};
use serde_json::Value;
let mut result = cluster.query("select name, type from `travel-sample` limit 5", None)
    .wait()
    .expect("Could not perform query");

println!("Rows:\n{:?}", result.rows_as().wait().collect::<Vec<Result<Value, CouchbaseError>>>());
println!("Meta:\n{:?}", result.meta().wait().expect("Could not get query meta"));

pub fn analytics_query<S>(
    &self,
    statement: S,
    options: Option<AnalyticsOptions>
) -> impl Future<Item = AnalyticsResult, Error = CouchbaseError> where
    S: Into<String>, 
[src]

Performs a query against the analytics service.

For now, please make sure to open one bucket (doesn't matter which one) before performing a cluster-level analytics query. This limiation will be lifted in the future, but for now the client needs an open bucket so it knows where internally to route the query.

Arguments

  • statement - The analytics query string itself.
  • options - Options to customize the default behavior.

Examples

use couchbase::{CouchbaseError, Cluster};
use futures::{Stream, Future};
use serde_json::Value;
let mut result = cluster
    .analytics_query("SELECT DataverseName FROM Metadata.`Dataverse`", None)
    .wait()
    .expect("Could not perform analytics query");

println!("---> rows {:?}", result.rows_as().wait().collect::<Vec<Result<Value, CouchbaseError>>>());
println!("---> meta {:?}", result.meta().wait().expect("Could not get analytics meta"));

pub fn disconnect(&mut self) -> Result<(), CouchbaseError>[src]

Disconnects this cluster and all associated open buckets.

Examples

cluster.disconnect().expect("Could not shutdown properly");

Auto Trait Implementations

impl !Send for Cluster

impl !Sync for Cluster

Blanket Implementations

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

impl<T> From<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<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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