use crate::Error;
use arangors_lite::Collection;
use std::ops::Deref;
#[derive(Debug, Clone)]
pub struct DatabaseCollection {
collection: Collection,
}
impl DatabaseCollection {
#[must_use]
#[inline]
pub fn name(&self) -> &str {
self.collection.name()
}
#[maybe_async::maybe_async]
pub async fn record_count(&self) -> Result<u32, Error> {
let properties = match self.collection.document_count().await {
Ok(value) => value,
Err(client_error) => return Err(Error::from(client_error)),
};
properties.info.count.map_or(Ok(0), Ok)
}
}
impl From<Collection> for DatabaseCollection {
fn from(collection: Collection) -> Self {
Self { collection }
}
}
impl Deref for DatabaseCollection {
type Target = Collection;
fn deref(&self) -> &Self::Target {
&self.collection
}
}