[][src]Struct couch_rs::Client

pub struct Client {
    pub uri: String,
    pub db_prefix: String,
    // some fields omitted
}

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

uri: Stringdb_prefix: String

Implementations

impl Client[src]

pub fn new(uri: &str) -> Result<Client, CouchError>[src]

new creates a new Couch client with a default timeout of 5 seconds. The URI has to be in this format: http://hostname:5984, for example: http://192.168.64.5:5984

pub fn new_with_timeout(uri: &str, timeout: u64) -> Result<Client, CouchError>[src]

new_with_timeout creates a new Couch client. The URI has to be in this format: http://hostname:5984, timeout is in seconds.

pub fn get_self(&mut self) -> &mut Self[src]

pub fn set_uri(&mut self, uri: String) -> &Self[src]

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

pub fn gzip(&mut self, enabled: bool) -> Result<&Self, CouchError>[src]

pub fn timeout(&mut self, to: u64) -> Result<&Self, CouchError>[src]

pub async fn list_dbs<'_>(&'_ self) -> Result<Vec<String>, CouchError>[src]

List the databases in CouchDB

Usage:

use std::error::Error;

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

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

pub async fn db<'_, '_>(
    &'_ self,
    dbname: &'_ str
) -> Result<Database, CouchError>
[src]

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

pub async fn make_db<'_, '_>(
    &'_ self,
    dbname: &'_ str
) -> Result<Database, CouchError>
[src]

pub async fn destroy_db<'_, '_>(
    &'_ self,
    dbname: &'_ str
) -> Result<bool, CouchError>
[src]

pub async fn check_status<'_>(&'_ self) -> Result<CouchStatus, CouchError>[src]

pub fn req(
    &self,
    method: Method,
    path: String,
    opts: Option<HashMap<String, String>>
) -> Result<RequestBuilder, CouchError>
[src]

pub fn get(
    &self,
    path: String,
    args: Option<HashMap<String, String>>
) -> Result<RequestBuilder, CouchError>
[src]

pub fn post(
    &self,
    path: String,
    body: String
) -> Result<RequestBuilder, CouchError>
[src]

pub fn put(
    &self,
    path: String,
    body: String
) -> Result<RequestBuilder, CouchError>
[src]

pub fn head(
    &self,
    path: String,
    args: Option<HashMap<String, String>>
) -> Result<RequestBuilder, CouchError>
[src]

pub fn delete(
    &self,
    path: String,
    args: Option<HashMap<String, String>>
) -> Result<RequestBuilder, CouchError>
[src]

Trait Implementations

impl Clone for Client[src]

impl Debug for Client[src]

Auto Trait Implementations

impl !RefUnwindSafe for Client

impl Send for Client

impl Sync for Client

impl Unpin for Client

impl !UnwindSafe for Client

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> Sealed<T> for T where
    T: ?Sized

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.