Struct couch_rs::Client

source ·
pub struct Client {
    pub db_prefix: String,
    /* private fields */
}
Expand description

Client handles the URI manipulation logic and the HTTP calls to the CouchDB REST API. It is also responsible for the creation/access/destruction of databases.

Fields§

§db_prefix: String

Implementations§

source§

impl Client

source

pub fn new(uri: &str, username: &str, password: &str) -> CouchResult<Client>

new creates a new Couch client with a default timeout of 10 seconds. The timeout is applied from when the request starts connecting until the response body has finished. The URI has to be in this format: http://hostname:5984, for example: http://192.168.64.5:5984

source

pub fn new_no_auth(uri: &str) -> CouchResult<Client>

new_no_auth creates a new Couch client with a default timeout of 10 seconds. Without authentication. The timeout is applied from when the request starts connecting until the response body has finished. The URI has to be in this format: http://hostname:5984, for example: http://192.168.64.5:5984

source

pub fn new_local_test() -> CouchResult<Client>

new_local_test creates a new Couch client for testing purposes with a default timeout of 10 seconds. The timeout is applied from when the request starts connecting until the response body has finished. The URI that will be used is: http://hostname:5984, with a username of “admin” and a password of “password”. Use this only for testing!!!

source

pub fn new_with_timeout( uri: &str, username: Option<&str>, password: Option<&str>, timeout: Option<u64> ) -> CouchResult<Client>

new_with_timeout creates a new Couch client. The URI has to be in this format: http://hostname:5984, The timeout is applied from when the request starts connecting until the response body has finished. Timeout is in seconds.

§Panics

Panics when the AUTHORIZATION header can not be set on the request.

source

pub fn get_self(&mut self) -> &mut Self

source

pub fn set_uri(&mut self, uri: &str) -> CouchResult<&Self>

source

pub fn set_prefix(&mut self, prefix: String) -> &Self

source

pub async fn list_dbs(&self) -> CouchResult<Vec<String>>

List the databases in CouchDB

Usage:

use std::error::Error;

const DB_HOST: &str = "http://localhost:5984";
const DB_USER: &str = "admin";
const DB_PW: &str = "password";
const TEST_DB: &str = "test_db";

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let client = couch_rs::Client::new(DB_HOST, DB_USER, DB_PW)?;
    let db = client.db(TEST_DB).await?;
    let dbs = client.list_dbs().await?;
    dbs.iter().for_each(|db| println!("Database: {}", db));
    Ok(())
}
source

pub async fn db(&self, dbname: &str) -> CouchResult<Database>

Connect to an existing database, or create a new one, when this one does not exist.

source

pub async fn make_db(&self, dbname: &str) -> CouchResult<Database>

Create a new database with the given name

source

pub async fn destroy_db(&self, dbname: &str) -> CouchResult<bool>

Destroy the database with the given name

source

pub async fn get_info(&self, dbname: &str) -> CouchResult<DbInfo>

Gets information about the specified database. See common for more details.

source

pub async fn check_status(&self) -> CouchResult<CouchStatus>

Returns meta information about the instance. The response contains information about the server, including a welcome message and the version of the server. See common for more details.

source

pub async fn membership(&self) -> CouchResult<Membership>

Returns membership information about the cluster. See _membership for more details.

source

pub async fn cluster_setup( &self, request: EnsureDbsExist ) -> CouchResult<ClusterSetup>

Returns cluster_setup information about the cluster. See _cluster_setup for more details.

source

pub fn req( &self, method: Method, path: &str, opts: Option<&HashMap<String, String>> ) -> RequestBuilder

Trait Implementations§

source§

impl Clone for Client

source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Client

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more