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
sourceimpl CouchDB
impl CouchDB
sourcepub fn with_config(config: Config) -> Result<Self>
pub fn with_config(config: Config) -> Result<Self>
Create a new client with config. TODO: Remove Ok-wrapping
pub fn with_config_and_client(config: Config, client: Client) -> Self
sourcepub fn with_url<S>(url: Option<S>) -> Result<Self>where
S: AsRef<str>,
pub fn with_url<S>(url: Option<S>) -> Result<Self>where
S: AsRef<str>,
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
sourcepub async fn init(&self) -> Result<()>
pub async fn init(&self) -> Result<()>
Init the database.
This creates the database if it does not exists. It should be called before calling other methods on the client.
pub async fn destroy_and_init(&self) -> Result<()>
sourcepub async fn get_many(&self, ids: &[&str]) -> Result<DocList>
pub async fn get_many(&self, ids: &[&str]) -> Result<DocList>
Get many docs by their ID from the database.
sourcepub async fn get_all_with_prefix(&self, prefix: &str) -> Result<DocList>
pub async fn get_all_with_prefix(&self, prefix: &str) -> Result<DocList>
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.
sourcepub async fn get_all_with_params(
&self,
params: &impl Serialize
) -> Result<DocList>
pub async fn get_all_with_params(
&self,
params: &impl Serialize
) -> Result<DocList>
Get all docs while passing a map of params.
sourcepub async fn delete_doc(&self, id: &str) -> Result<PutResponse>
pub async fn delete_doc(&self, id: &str) -> Result<PutResponse>
Delete a doc by its id
sourcepub async fn put_doc(&self, doc: Doc) -> Result<PutResponse>
pub async fn put_doc(&self, doc: Doc) -> Result<PutResponse>
Put a doc into the database.
sourcepub async fn put_bulk(&self, docs: Vec<Doc>) -> Result<Vec<PutResult>>
pub async fn put_bulk(&self, docs: Vec<Doc>) -> Result<Vec<PutResult>>
Put a list of docs into the database in a single bulk operation.
sourcepub async fn put_bulk_update<T>(&self, docs: Vec<T>) -> Result<Vec<PutResult>>where
T: Into<Doc>,
pub async fn put_bulk_update<T>(&self, docs: Vec<T>) -> Result<Vec<PutResult>>where
T: Into<Doc>,
Put a list of docs into the database in a single bulk operation, while first fetching the latest rev for each doc.
sourcepub fn changes(&self, last_seq: Option<String>) -> ChangesStream
pub fn changes(&self, last_seq: Option<String>) -> ChangesStream
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);
}
}
pub async fn get_last_seq(&self) -> Result<String>
sourceimpl CouchDB
impl CouchDB
pub fn table<T: TypedValue>(&self) -> Table<T>
sourceimpl CouchDB
impl CouchDB
Methods on the CouchDB client that directly take or return Records.
sourcepub async fn get_all_records<T: TypedValue>(&self) -> Result<Vec<Record<T>>>
pub async fn get_all_records<T: TypedValue>(&self) -> Result<Vec<Record<T>>>
Get all records with the type from the database.
sourcepub async fn get_record<T: TypedValue>(&self, id: &str) -> Result<Record<T>>
pub async fn get_record<T: TypedValue>(&self, id: &str) -> Result<Record<T>>
Get a single record by its type and id.
let record = db.get_record::<Media>("someidstring").await?;
pub async fn get_record_untyped(&self, guid: &str) -> Result<UntypedRecord>
pub async fn get_many_records<T: TypedValue>(
&self,
ids: &[&str]
) -> Result<Vec<Record<T>>>
pub async fn get_many_records_untyped(
&self,
ids: &[&str]
) -> Result<Vec<UntypedRecord>>
sourcepub async fn put_record<T: TypedValue>(
&self,
record: Record<T>
) -> Result<PutResponse>
pub async fn put_record<T: TypedValue>(
&self,
record: Record<T>
) -> Result<PutResponse>
Put a single record into the database.
sourcepub async fn put_record_bulk<T: TypedValue>(
&self,
records: Vec<Record<T>>
) -> Result<Vec<PutResult>>
pub async fn put_record_bulk<T: TypedValue>(
&self,
records: Vec<Record<T>>
) -> Result<Vec<PutResult>>
Put a vector of records into the database in a single operation.
sourcepub async fn put_untyped_record_bulk(
&self,
records: Vec<UntypedRecord>
) -> Result<Vec<PutResult>>
pub async fn put_untyped_record_bulk(
&self,
records: Vec<UntypedRecord>
) -> Result<Vec<PutResult>>
Put a vector of untyped records into the database in a single operation.
sourcepub async fn put_record_bulk_update<T: TypedValue>(
&self,
records: Vec<Record<T>>
) -> Result<Vec<PutResult>>
pub async fn put_record_bulk_update<T: TypedValue>(
&self,
records: Vec<Record<T>>
) -> Result<Vec<PutResult>>
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.
sourcepub async fn put_untyped_record_bulk_update(
&self,
records: Vec<UntypedRecord>
) -> Result<Vec<PutResult>>
pub async fn put_untyped_record_bulk_update(
&self,
records: Vec<UntypedRecord>
) -> Result<Vec<PutResult>>
Put a vector of untyped records into the database in a single operation.
sourcepub async fn delete_record(&self, guid: &str) -> Result<PutResponse>
pub async fn delete_record(&self, guid: &str) -> Result<PutResponse>
Delete a single record from the database.
pub async fn apply_patches_with_callback(
&self,
patches: HashMap<String, Patch>,
cb: impl FnMut(&mut Vec<UntypedRecord>)
) -> Result<Vec<String>>
Trait Implementations
sourceimpl<'impl0> Resolver for &'impl0 CouchDB
impl<'impl0> Resolver for &'impl0 CouchDB
type Error = CouchError
sourcefn resolve<'life0, 'life1, 'async_trait, T: TypedValue>(
&'life0 self,
id: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Record<T>, Self::Error>> + Send + 'async_trait>>where
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn resolve<'life0, 'life1, 'async_trait, T: TypedValue>(
&'life0 self,
id: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Record<T>, Self::Error>> + Send + 'async_trait>>where
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
sourcefn resolve_all<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
ids: &'life1 [&'life2 str]
) -> Pin<Box<dyn Future<Output = Vec<Result<TypedRecord<T>, Self::Error>, Global>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
T: TypedValue + Send + 'async_trait,
Self: 'async_trait + Sync,
fn resolve_all<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
ids: &'life1 [&'life2 str]
) -> Pin<Box<dyn Future<Output = Vec<Result<TypedRecord<T>, Self::Error>, Global>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
T: TypedValue + Send + 'async_trait,
Self: 'async_trait + Sync,
fn resolve_all_refs<'life0, 'life1, 'async_trait, T>(
&'life0 self,
records: &'life1 mut [TypedRecord<T>]
) -> Pin<Box<dyn Future<Output = Result<(), MissingRefsError>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: Resolvable + Send + 'async_trait,
Self: Send + 'async_trait + Sync,
sourcefn resolve_refs<'life0, 'life1, 'async_trait, T>(
&'life0 self,
references: &'life1 mut [Reference<T>]
) -> Pin<Box<dyn Future<Output = Result<(), MissingRefsError>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: TypedValue + Send + 'async_trait,
Self: 'async_trait + Sync,
fn resolve_refs<'life0, 'life1, 'async_trait, T>(
&'life0 self,
references: &'life1 mut [Reference<T>]
) -> Pin<Box<dyn Future<Output = Result<(), MissingRefsError>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: TypedValue + Send + 'async_trait,
Self: 'async_trait + Sync,
sourceimpl Resolver for CouchDB
impl Resolver for CouchDB
type Error = CouchError
sourcefn resolve<'life0, 'life1, 'async_trait, T: TypedValue>(
&'life0 self,
id: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Record<T>, Self::Error>> + Send + 'async_trait>>where
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn resolve<'life0, 'life1, 'async_trait, T: TypedValue>(
&'life0 self,
id: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Record<T>, Self::Error>> + Send + 'async_trait>>where
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
sourcefn resolve_all<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
ids: &'life1 [&'life2 str]
) -> Pin<Box<dyn Future<Output = Vec<Result<TypedRecord<T>, Self::Error>, Global>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
T: TypedValue + Send + 'async_trait,
Self: 'async_trait + Sync,
fn resolve_all<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
ids: &'life1 [&'life2 str]
) -> Pin<Box<dyn Future<Output = Vec<Result<TypedRecord<T>, Self::Error>, Global>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
T: TypedValue + Send + 'async_trait,
Self: 'async_trait + Sync,
fn resolve_all_refs<'life0, 'life1, 'async_trait, T>(
&'life0 self,
records: &'life1 mut [TypedRecord<T>]
) -> Pin<Box<dyn Future<Output = Result<(), MissingRefsError>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: Resolvable + Send + 'async_trait,
Self: Send + 'async_trait + Sync,
sourcefn resolve_refs<'life0, 'life1, 'async_trait, T>(
&'life0 self,
references: &'life1 mut [Reference<T>]
) -> Pin<Box<dyn Future<Output = Result<(), MissingRefsError>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: TypedValue + Send + 'async_trait,
Self: 'async_trait + Sync,
fn resolve_refs<'life0, 'life1, 'async_trait, T>(
&'life0 self,
references: &'life1 mut [Reference<T>]
) -> Pin<Box<dyn Future<Output = Result<(), MissingRefsError>> + Send + 'async_trait, Global>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: TypedValue + Send + 'async_trait,
Self: 'async_trait + Sync,
Auto Trait Implementations
impl !RefUnwindSafe for CouchDB
impl Send for CouchDB
impl Sync for CouchDB
impl Unpin for CouchDB
impl !UnwindSafe for CouchDB
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
fn into_collection<A>(self) -> SmallVec<A>where
A: Array<Item = T>,
fn into_collection<A>(self) -> SmallVec<A>where
A: Array<Item = T>,
self
into a collection.fn mapped<U, F, A>(self, f: F) -> SmallVec<A>where
F: FnMut(T) -> U,
A: Array<Item = U>,
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Self