[][src]Struct couchbase::Cluster

pub struct Cluster { /* fields omitted */ }

Connect to a Couchbase cluster and perform cluster-level operations

This Cluster object is also your main and only entry point into the SDK.

Implementations

impl Cluster[src]

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

Connect to a couchbase cluster

Arguments

  • connection_string - the connection string containing the bootstrap hosts
  • username - the name of the user, used for authentication
  • password - the password of the user

Examples

Connecting to localhost with the username and its password.

let cluster = Cluster::connect("127.0.0.1", "username", "password");

Using three nodes for bootstrapping (recommended for production):

let cluster = Cluster::connect("couchbase://hosta,hostb,hostc", "username", "password");

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

Open and connect to a couchbase Bucket

Arguments

  • name - the name of the bucket

Examples

Connect and open the travel-sample bucket.

let cluster = Cluster::connect("127.0.0.1", "username", "password");
let bucket = cluster.bucket("travel-sample");

pub async fn query<S: Into<String>, '_>(
    &'_ self,
    statement: S,
    options: QueryOptions
) -> CouchbaseResult<QueryResult>
[src]

Executes a N1QL statement

Arguments

  • statement - the N1QL statement to execute
  • options - allows to pass in custom options

Examples

Run a N1QL query with default options.

let result = cluster.query("select * from bucket", QueryOptions::default());

This will return an async result, which can be consumed:

match cluster.query("select 1=1", QueryOptions::default()).await {
    Ok(mut result) => {
        for row in result.rows::<serde_json::Value>().next().await {
            println!("Found Row {:?}", row);
        }
    },
    Err(e) => panic!("Query failed: {:?}", e),
}

See the QueryResult for more information on what and how it can be consumed.

pub async fn analytics_query<S: Into<String>, '_>(
    &'_ self,
    statement: S,
    options: AnalyticsOptions
) -> CouchbaseResult<AnalyticsResult>
[src]

Executes an analytics query

Arguments

  • statement - the analyticss statement to execute
  • options - allows to pass in custom options

Examples

Run an analytics query with default options.

let result = cluster.analytics_query("select * from dataset", AnalyticsOptions::default());

This will return an async result, which can be consumed:

match cluster.query("select 1=1", AnalyticsOptions::default()).await {
    Ok(mut result) => {
        for row in result.rows::<serde_json::Value>().next().await {
            println!("Found Row {:?}", row);
        }
    },
    Err(e) => panic!("Query failed: {:?}", e),
}

See the AnalyticsResult for more information on what and how it can be consumed.

pub async fn search_query<S: Into<String>, T: SearchQuery, '_>(
    &'_ self,
    index: S,
    query: T,
    options: SearchOptions
) -> CouchbaseResult<SearchResult>
[src]

Executes a search query

Arguments

  • index - the search index name to use
  • query - the search query to perform
  • options - allows to pass in custom options

Examples

Run a search query with default options.

let result = cluster.search_query(
   String::from("test"),
   QueryStringQuery::new(String::from("swanky")),
   SearchOptions::default(),
);

This will return an async result, which can be consumed:

match cluster.cluster.search_query(
   String::from("test"),
   QueryStringQuery::new(String::from("swanky")),
   SearchOptions::default(),
).await {
    Ok(mut result) => {
        for row in result.rows::<serde_json::Value>().next().await {
            println!("Found Row {:?}", row);
        }
    },
    Err(e) => panic!("Query failed: {:?}", e),
}

See the SearchResult for more information on what and how it can be consumed.

pub fn users(&self) -> UserManager[src]

Returns a new UserManager

Arguments

Examples

Connect and open the travel-sample bucket.

let cluster = Cluster::connect("127.0.0.1", "username", "password");
let bucket = cluster.U("travel-sample");

Auto Trait Implementations

impl !RefUnwindSafe for Cluster

impl Send for Cluster

impl Sync for Cluster

impl Unpin for Cluster

impl !UnwindSafe for Cluster

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, U> Into<U> for T where
    U: From<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>,