[][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, username: &str, password: &str) -> CouchResult<Client>[src]

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

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

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

pub fn new_local_test() -> CouchResult<Client>[src]

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!!!

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

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.

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 async fn list_dbs<'_>(&'_ self) -> CouchResult<Vec<String>>[src]

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(())
}

pub async fn db<'_, '_>(&'_ self, dbname: &'_ str) -> CouchResult<Database>[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) -> CouchResult<Database>[src]

Create a new database with the given name

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

Destroy the database with the given name

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

Checks if a database exists

Usage:

use couch_rs::error::CouchResult;

const TEST_DB: &str = "test_db";

#[tokio::main]
async fn main() -> CouchResult<()> {
    let client = couch_rs::Client::new_local_test()?;
    let db = client.db(TEST_DB).await?;

    if db.exists(TEST_DB).await {
        println!("The database exists");
    }

    return Ok(());
}

pub async fn get_info<'_, '_>(&'_ self, dbname: &'_ str) -> CouchResult<DbInfo>[src]

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

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

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.

pub fn req(
    &self,
    method: Method,
    path: String,
    opts: Option<HashMap<String, String>>
) -> CouchResult<RequestBuilder>
[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> Instrument for T[src]

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

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.