use std::fmt::Debug;
use super::{gridfs::GridFsBucket, Collection};
use crate::{
options::{
CollectionOptions,
GridFsBucketOptions,
ReadConcern,
SelectionCriteria,
WriteConcern,
},
Database as AsyncDatabase,
};
#[derive(Debug, Clone)]
pub struct Database {
pub(crate) async_database: AsyncDatabase,
}
impl Database {
pub(crate) fn new(async_database: AsyncDatabase) -> Self {
Self { async_database }
}
pub fn name(&self) -> &str {
self.async_database.name()
}
pub fn selection_criteria(&self) -> Option<&SelectionCriteria> {
self.async_database.selection_criteria()
}
pub fn read_concern(&self) -> Option<&ReadConcern> {
self.async_database.read_concern()
}
pub fn write_concern(&self) -> Option<&WriteConcern> {
self.async_database.write_concern()
}
pub fn collection<T: Send + Sync>(&self, name: &str) -> Collection<T> {
Collection::new(self.async_database.collection(name))
}
pub fn collection_with_options<T: Send + Sync>(
&self,
name: &str,
options: CollectionOptions,
) -> Collection<T> {
Collection::new(self.async_database.collection_with_options(name, options))
}
pub fn gridfs_bucket(&self, options: impl Into<Option<GridFsBucketOptions>>) -> GridFsBucket {
GridFsBucket::new(self.async_database.gridfs_bucket(options))
}
}