use arangors_lite::Database;
use crate::db::database_collection::DatabaseCollection;
use crate::db::database_service::{query_records, query_records_in_batches};
use crate::query::{Query, QueryCursor, QueryResult};
use crate::undefined_record::UndefinedRecord;
use crate::{Error, OperationOptions};
#[maybe_async::maybe_async]
pub trait DatabaseAccess: Sync {
#[must_use]
fn operation_options(&self) -> OperationOptions {
OperationOptions::default()
}
fn collection(&self, collection: &str) -> Option<&DatabaseCollection>;
fn get_collection(&self, collection: &str) -> Result<&DatabaseCollection, Error> {
self.collection(collection).ok_or(Error::NotFound {
item: "Collection".to_string(),
id: collection.to_string(),
source: None,
})
}
#[must_use]
fn database(&self) -> &Database;
async fn query(&self, query: &Query) -> Result<QueryResult<UndefinedRecord>, Error> {
query_records(self, query).await
}
async fn query_in_batches(
&self,
query: &Query,
batch_size: u32,
) -> Result<QueryCursor<UndefinedRecord>, Error> {
query_records_in_batches(self, query, batch_size).await
}
}