pub struct CouchDB { /* private fields */ }
Expand description

CouchDB client.

The client is stateless. It only contains a HTTP client and the config on how to connect to a database.

Implementations

Create a new client with config. TODO: Remove Ok-wrapping

Create a new client with a CouchDB URL.

The URL should have the following format: http://username:password@hostname:5984/dbname If passing None for url a client will be created with the default address http://localhost:5984/oas

Init the database.

This creates the database if it does not exists. It should be called before calling other methods on the client.

Get all docs from the database.

Get many docs by their ID from the database.

Get all docs where the couch id starts with a prefix.

When the ids contain a type prefix (e.g. “oas.Media_someidstring”, then this method can be used to get all docs with a type.

Get all docs while passing a map of params.

Get a doc from the id by its id.

Delete a doc by its id

Put a doc into the database.

Put a list of docs into the database in a single bulk operation.

Put a list of docs into the database in a single bulk operation, while first fetching the latest rev for each doc.

Get a stream of changes from the database.

Some options can be set on the ChangesStream, see ChangesStream.

Example:

let config = Config::with_defaults("some_db".into());
let db = CouchDB::with_config(config)?;
let mut stream = db.changes(None);
while let Some(event) = stream.next().await {
    let event = event.unwrap();
    if let Some(doc) = event.doc {
        eprintln!("new doc or rev: {:?}", doc);
    }
}

Methods on the CouchDB client that directly take or return Records.

Get all records with the type from the database.

Get a single record by its type and id.

let record = db.get_record::<Media>("someidstring").await?;

Put a single record into the database.

Put a vector of records into the database in a single operation.

Put a vector of untyped records into the database in a single operation.

Put a vector of records into the database in a single operation, while first fetching the lastest rev for records that do not have a rev set.

Put a vector of untyped records into the database in a single operation.

Delete a single record from the database.

Apply a list of JSON patches.

patches is a HashMap with GUIDs as keys and JSON patches as values.

TODO: Make this atomic!

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Resolve (load) a single record by its id.
Resolve (load) all records with their ids. Read more
Resolve a list of references.
Resolve (load) a single record by its id.
Resolve (load) all records with their ids. Read more
Resolve a list of references.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts self into a collection.
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more