[−][src]Struct couchbase::Cluster
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]
connection_string: S,
username: S,
password: S
) -> Result<Self, CouchbaseError> where
S: Into<String>,
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]
S: Into<String>,
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]
&self,
statement: S,
options: Option<QueryOptions>
) -> impl Future<Item = QueryResult, Error = CouchbaseError> where
S: Into<String>,
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]
&self,
statement: S,
options: Option<AnalyticsOptions>
) -> impl Future<Item = AnalyticsResult, Error = CouchbaseError> where
S: Into<String>,
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
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for 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<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,