[−][src]Struct chesterfield::Database
Interface for interacting with a specific CouchDB database within a CouchDB node.
Example
use chesterfield::Client; let couchdb_url = "https://localhost:5984"; let db = "collection"; let client = Client::new(couchdb_url).unwrap(); let database = client.database(db).unwrap();
Methods
impl Database
[src]
pub fn create(&self) -> impl Future<Item = (), Error = Error>
[src]
Create the database, if it doesn't exist.
Creating the database object itself is lazy- no check is performed that the endpoint exists. Call this method if you need to create the endpoint (or if you're not sure).
Example
use chesterfield::Client; use tokio::prelude::Future; let client = Client::new("http://localhost:5984").unwrap(); let database = client.database("items").unwrap(); tokio::run( database.create() .map_err(|e| { println!("{}", e); }) );
pub fn exists(&self) -> impl Future<Item = bool, Error = Error>
[src]
Check whether the database exists
pub fn get(&self, id: impl Into<String>) -> GetRequest
[src]
Retrieve a document from a database.
Example
use chesterfield::Client; let couchdb_url = "https://localhost:5984"; let db = "collection"; let document_id = "some-unique-id"; let client = Client::new(couchdb_url).unwrap(); let database = client.database(db).unwrap(); let get_request = database.get(document_id);
pub fn insert<'a, T: Serialize>(
&self,
document: &'a T,
id: impl Into<Option<String>>
) -> InsertRequest<'a, T>
[src]
&self,
document: &'a T,
id: impl Into<Option<String>>
) -> InsertRequest<'a, T>
Insert pretty much anything into the database.
Provided that is, that it implements Serialize.
You can optionally provide an id. If you don't, CouchDB will assign one for you (but you might not like it). The response will contain the ID and the revision.
Example
#[derive(Serialize)] struct MyCoolStruct { field1: String, field2: u32, } let doc = MyCoolStruct { field1: String::from("some string"), field2: 42, }; tokio::run( database // insert document into database .insert(&doc, None) .send() // do something with the response .map(|response| assert!(response.ok)) // handle any errors .map_err(|e| panic!("{}", e)), );
pub fn update<'a, T: Serialize>(
&self,
document: &'a T,
id: impl Into<String>,
rev: impl Into<String>
) -> UpdateRequest<'a, T>
[src]
&self,
document: &'a T,
id: impl Into<String>,
rev: impl Into<String>
) -> UpdateRequest<'a, T>
pub fn delete(
&self,
id: impl Into<String>,
rev: impl Into<String>
) -> DeleteRequest
[src]
&self,
id: impl Into<String>,
rev: impl Into<String>
) -> DeleteRequest
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Erased for T
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,