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
impl Client
sourcepub fn new(uri: &str, username: &str, password: &str) -> CouchResult<Client>
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
sourcepub fn new_no_auth(uri: &str) -> CouchResult<Client>
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
sourcepub fn new_local_test() -> CouchResult<Client>
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!!!
sourcepub fn new_with_timeout(
uri: &str,
username: Option<&str>,
password: Option<&str>,
timeout: Option<u64>
) -> CouchResult<Client>
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.
pub fn get_self(&mut self) -> &mut Self
pub fn set_uri(&mut self, uri: &str) -> CouchResult<&Self>
pub fn set_prefix(&mut self, prefix: String) -> &Self
sourcepub async fn list_dbs(&self) -> CouchResult<Vec<String>>
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(())
}
sourcepub async fn db(&self, dbname: &str) -> CouchResult<Database>
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.
sourcepub async fn make_db(&self, dbname: &str) -> CouchResult<Database>
pub async fn make_db(&self, dbname: &str) -> CouchResult<Database>
Create a new database with the given name
sourcepub async fn destroy_db(&self, dbname: &str) -> CouchResult<bool>
pub async fn destroy_db(&self, dbname: &str) -> CouchResult<bool>
Destroy the database with the given name
sourcepub async fn get_info(&self, dbname: &str) -> CouchResult<DbInfo>
pub async fn get_info(&self, dbname: &str) -> CouchResult<DbInfo>
Gets information about the specified database. See common for more details.
sourcepub async fn check_status(&self) -> CouchResult<CouchStatus>
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.
sourcepub async fn membership(&self) -> CouchResult<Membership>
pub async fn membership(&self) -> CouchResult<Membership>
Returns membership information about the cluster. See _membership for more details.
sourcepub async fn cluster_setup(
&self,
request: EnsureDbsExist
) -> CouchResult<ClusterSetup>
pub async fn cluster_setup( &self, request: EnsureDbsExist ) -> CouchResult<ClusterSetup>
Returns cluster_setup
information about the cluster.
See _cluster_setup for more details.