[][src]Struct chesterfield::Database

pub struct Database { /* fields omitted */ }

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]

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]

pub fn delete(
    &self,
    id: impl Into<String>,
    rev: impl Into<String>
) -> DeleteRequest
[src]

Auto Trait Implementations

impl Send for Database

impl Sync for Database

Blanket Implementations

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

impl<T> From<T> for T[src]

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.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T

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

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