use std::fmt::Display;
use crate::{
database::transactions::Transaction,
direct_access::repository_factory,
entities::Workspace,
event::{DirectAccessEntity, EntityEvent, Event, EventBuffer, Origin},
snapshot::EntityTreeSnapshot,
types::EntityId,
};
use crate::direct_access::root::RootRelationshipField;
use crate::error::RepositoryError;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum WorkspaceRelationshipField {
Entities,
Features,
Global,
UserInterface,
}
impl Display for WorkspaceRelationshipField {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
pub trait WorkspaceTable {
fn create(&mut self, entity: &Workspace) -> Result<Workspace, RepositoryError>;
fn create_multi(&mut self, entities: &[Workspace]) -> Result<Vec<Workspace>, RepositoryError>;
fn get(&self, id: &EntityId) -> Result<Option<Workspace>, RepositoryError>;
fn get_multi(&self, ids: &[EntityId]) -> Result<Vec<Option<Workspace>>, RepositoryError>;
fn get_all(&self) -> Result<Vec<Workspace>, RepositoryError>;
fn update(&mut self, entity: &Workspace) -> Result<Workspace, RepositoryError>;
fn update_multi(&mut self, entities: &[Workspace]) -> Result<Vec<Workspace>, RepositoryError>;
fn update_with_relationships(
&mut self,
entity: &Workspace,
) -> Result<Workspace, RepositoryError>;
fn update_with_relationships_multi(
&mut self,
entities: &[Workspace],
) -> Result<Vec<Workspace>, RepositoryError>;
fn remove(&mut self, id: &EntityId) -> Result<(), RepositoryError>;
fn remove_multi(&mut self, ids: &[EntityId]) -> Result<(), RepositoryError>;
fn get_relationship(
&self,
id: &EntityId,
field: &WorkspaceRelationshipField,
) -> Result<Vec<EntityId>, RepositoryError>;
fn get_relationship_many(
&self,
ids: &[EntityId],
field: &WorkspaceRelationshipField,
) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>, RepositoryError>;
fn get_relationship_count(
&self,
id: &EntityId,
field: &WorkspaceRelationshipField,
) -> Result<usize, RepositoryError>;
fn get_relationship_in_range(
&self,
id: &EntityId,
field: &WorkspaceRelationshipField,
offset: usize,
limit: usize,
) -> Result<Vec<EntityId>, RepositoryError>;
fn get_relationships_from_right_ids(
&self,
field: &WorkspaceRelationshipField,
right_ids: &[EntityId],
) -> Result<Vec<(EntityId, Vec<EntityId>)>, RepositoryError>;
fn set_relationship_multi(
&mut self,
field: &WorkspaceRelationshipField,
relationships: Vec<(EntityId, Vec<EntityId>)>,
) -> Result<(), RepositoryError>;
fn set_relationship(
&mut self,
id: &EntityId,
field: &WorkspaceRelationshipField,
right_ids: &[EntityId],
) -> Result<(), RepositoryError>;
fn move_relationship_ids(
&mut self,
id: &EntityId,
field: &WorkspaceRelationshipField,
ids_to_move: &[EntityId],
new_index: i32,
) -> Result<Vec<EntityId>, RepositoryError>;
}
pub trait WorkspaceTableRO {
fn get(&self, id: &EntityId) -> Result<Option<Workspace>, RepositoryError>;
fn get_multi(&self, ids: &[EntityId]) -> Result<Vec<Option<Workspace>>, RepositoryError>;
fn get_all(&self) -> Result<Vec<Workspace>, RepositoryError>;
fn get_relationship(
&self,
id: &EntityId,
field: &WorkspaceRelationshipField,
) -> Result<Vec<EntityId>, RepositoryError>;
fn get_relationship_many(
&self,
ids: &[EntityId],
field: &WorkspaceRelationshipField,
) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>, RepositoryError>;
fn get_relationship_count(
&self,
id: &EntityId,
field: &WorkspaceRelationshipField,
) -> Result<usize, RepositoryError>;
fn get_relationship_in_range(
&self,
id: &EntityId,
field: &WorkspaceRelationshipField,
offset: usize,
limit: usize,
) -> Result<Vec<EntityId>, RepositoryError>;
fn get_relationships_from_right_ids(
&self,
field: &WorkspaceRelationshipField,
right_ids: &[EntityId],
) -> Result<Vec<(EntityId, Vec<EntityId>)>, RepositoryError>;
}
pub struct WorkspaceRepository<'a> {
table: Box<dyn WorkspaceTable + 'a>,
transaction: &'a Transaction,
}
impl<'a> WorkspaceRepository<'a> {
pub fn new(table: Box<dyn WorkspaceTable + 'a>, transaction: &'a Transaction) -> Self {
WorkspaceRepository { table, transaction }
}
pub fn create_orphan(
&mut self,
event_buffer: &mut EventBuffer,
entity: &Workspace,
) -> Result<Workspace, RepositoryError> {
let new = self.table.create(entity)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Workspace(EntityEvent::Created)),
ids: vec![new.id],
data: None,
});
Ok(new)
}
pub fn create_orphan_multi(
&mut self,
event_buffer: &mut EventBuffer,
entities: &[Workspace],
) -> Result<Vec<Workspace>, RepositoryError> {
let new_entities = self.table.create_multi(entities)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Workspace(EntityEvent::Created)),
ids: new_entities.iter().map(|e| e.id).collect(),
data: None,
});
Ok(new_entities)
}
pub fn create(
&mut self,
event_buffer: &mut EventBuffer,
entity: &Workspace,
owner_id: EntityId,
_index: i32,
) -> Result<Workspace, RepositoryError> {
let new = self.table.create(entity)?;
let created_id = new.id;
let mut relationship_ids = self.get_relationships_from_owner(&owner_id)?;
if relationship_ids.is_empty() {
relationship_ids = vec![created_id];
} else {
self.remove_multi(event_buffer, &relationship_ids)?;
relationship_ids = vec![created_id];
}
self.set_relationships_in_owner(event_buffer, &owner_id, &relationship_ids)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Workspace(EntityEvent::Created)),
ids: vec![created_id],
data: None,
});
Ok(new)
}
pub fn create_multi(
&mut self,
event_buffer: &mut EventBuffer,
entities: &[Workspace],
owner_id: EntityId,
_index: i32,
) -> Result<Vec<Workspace>, RepositoryError> {
let new_entities = self.table.create_multi(entities)?;
let created_ids: Vec<EntityId> = new_entities.iter().map(|e| e.id).collect();
let mut relationship_ids = self.get_relationships_from_owner(&owner_id)?;
if relationship_ids.is_empty() {
relationship_ids = created_ids.clone();
} else {
self.remove_multi(event_buffer, &relationship_ids)?;
relationship_ids = created_ids.clone();
}
self.set_relationships_in_owner(event_buffer, &owner_id, &relationship_ids)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Workspace(EntityEvent::Created)),
ids: created_ids,
data: None,
});
Ok(new_entities)
}
pub fn get(&self, id: &EntityId) -> Result<Option<Workspace>, RepositoryError> {
self.table.get(id)
}
pub fn get_multi(&self, ids: &[EntityId]) -> Result<Vec<Option<Workspace>>, RepositoryError> {
self.table.get_multi(ids)
}
pub fn get_all(&self) -> Result<Vec<Workspace>, RepositoryError> {
self.table.get_all()
}
pub fn update(
&mut self,
event_buffer: &mut EventBuffer,
entity: &Workspace,
) -> Result<Workspace, RepositoryError> {
let updated = self.table.update(entity)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Workspace(EntityEvent::Updated)),
ids: vec![updated.id],
data: None,
});
Ok(updated)
}
pub fn update_multi(
&mut self,
event_buffer: &mut EventBuffer,
entities: &[Workspace],
) -> Result<Vec<Workspace>, RepositoryError> {
let updated = self.table.update_multi(entities)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Workspace(EntityEvent::Updated)),
ids: updated.iter().map(|e| e.id).collect(),
data: None,
});
Ok(updated)
}
pub fn update_with_relationships(
&mut self,
event_buffer: &mut EventBuffer,
entity: &Workspace,
) -> Result<Workspace, RepositoryError> {
let updated = self.table.update_with_relationships(entity)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Workspace(EntityEvent::Updated)),
ids: vec![updated.id],
data: None,
});
Ok(updated)
}
pub fn update_with_relationships_multi(
&mut self,
event_buffer: &mut EventBuffer,
entities: &[Workspace],
) -> Result<Vec<Workspace>, RepositoryError> {
let updated = self.table.update_with_relationships_multi(entities)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Workspace(EntityEvent::Updated)),
ids: updated.iter().map(|e| e.id).collect(),
data: None,
});
Ok(updated)
}
pub fn remove(
&mut self,
event_buffer: &mut EventBuffer,
id: &EntityId,
) -> Result<(), RepositoryError> {
let entity = match self.table.get(id)? {
Some(e) => e,
None => return Ok(()),
};
let global = entity.global;
let entities = entity.entities.clone();
let features = entity.features.clone();
let user_interface = entity.user_interface;
repository_factory::write::create_global_repository(self.transaction)?
.remove(event_buffer, &global)?;
repository_factory::write::create_entity_repository(self.transaction)?
.remove_multi(event_buffer, &entities)?;
repository_factory::write::create_feature_repository(self.transaction)?
.remove_multi(event_buffer, &features)?;
repository_factory::write::create_user_interface_repository(self.transaction)?
.remove(event_buffer, &user_interface)?;
let affected_owner_ids: Vec<EntityId> = {
let owner_repo = repository_factory::write::create_root_repository(self.transaction)?;
owner_repo
.get_relationships_from_right_ids(&RootRelationshipField::Workspace, &[*id])?
.into_iter()
.map(|(owner_id, _)| owner_id)
.collect()
};
let mut owner_rel_before: std::collections::HashMap<EntityId, Vec<EntityId>> =
std::collections::HashMap::new();
for owner_id in &affected_owner_ids {
owner_rel_before.insert(*owner_id, self.get_relationships_from_owner(owner_id)?);
}
self.table.remove(id)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Workspace(EntityEvent::Removed)),
ids: vec![*id],
data: None,
});
for owner_id in &affected_owner_ids {
if let Some(rel_ids) = owner_rel_before.get(owner_id) {
let updated: Vec<EntityId> =
rel_ids.iter().copied().filter(|rid| *rid != *id).collect();
self.set_relationships_in_owner(event_buffer, owner_id, &updated)?;
}
}
Ok(())
}
pub fn remove_multi(
&mut self,
event_buffer: &mut EventBuffer,
ids: &[EntityId],
) -> Result<(), RepositoryError> {
let entities = self.table.get_multi(ids)?;
if entities.is_empty() || entities.iter().all(|e| e.is_none()) {
return Ok(());
}
let global_ids: Vec<EntityId> = entities
.iter()
.filter_map(|entity| entity.as_ref().map(|entity| entity.global))
.collect();
let mut entities_ids: Vec<EntityId> = entities
.iter()
.flat_map(|entity| entity.as_ref().map(|entity| entity.entities.clone()))
.flatten()
.collect();
entities_ids.sort();
entities_ids.dedup();
let mut features_ids: Vec<EntityId> = entities
.iter()
.flat_map(|entity| entity.as_ref().map(|entity| entity.features.clone()))
.flatten()
.collect();
features_ids.sort();
features_ids.dedup();
let user_interface_ids: Vec<EntityId> = entities
.iter()
.filter_map(|entity| entity.as_ref().map(|entity| entity.user_interface))
.collect();
repository_factory::write::create_global_repository(self.transaction)?
.remove_multi(event_buffer, &global_ids)?;
repository_factory::write::create_entity_repository(self.transaction)?
.remove_multi(event_buffer, &entities_ids)?;
repository_factory::write::create_feature_repository(self.transaction)?
.remove_multi(event_buffer, &features_ids)?;
repository_factory::write::create_user_interface_repository(self.transaction)?
.remove_multi(event_buffer, &user_interface_ids)?;
let affected_owner_ids: Vec<EntityId> = {
let owner_repo = repository_factory::write::create_root_repository(self.transaction)?;
owner_repo
.get_relationships_from_right_ids(&RootRelationshipField::Workspace, ids)?
.into_iter()
.map(|(owner_id, _)| owner_id)
.collect()
};
let mut owner_rel_before: std::collections::HashMap<EntityId, Vec<EntityId>> =
std::collections::HashMap::new();
for owner_id in &affected_owner_ids {
owner_rel_before.insert(*owner_id, self.get_relationships_from_owner(owner_id)?);
}
self.table.remove_multi(ids)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Workspace(EntityEvent::Removed)),
ids: ids.into(),
data: None,
});
{
let removed_set: std::collections::HashSet<EntityId> = ids.iter().copied().collect();
for owner_id in &affected_owner_ids {
if let Some(rel_ids) = owner_rel_before.get(owner_id) {
let updated: Vec<EntityId> = rel_ids
.iter()
.copied()
.filter(|rid| !removed_set.contains(rid))
.collect();
self.set_relationships_in_owner(event_buffer, owner_id, &updated)?;
}
}
}
Ok(())
}
pub fn get_relationship(
&self,
id: &EntityId,
field: &WorkspaceRelationshipField,
) -> Result<Vec<EntityId>, RepositoryError> {
self.table.get_relationship(id, field)
}
pub fn get_relationship_many(
&self,
ids: &[EntityId],
field: &WorkspaceRelationshipField,
) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>, RepositoryError> {
self.table.get_relationship_many(ids, field)
}
pub fn get_relationship_count(
&self,
id: &EntityId,
field: &WorkspaceRelationshipField,
) -> Result<usize, RepositoryError> {
self.table.get_relationship_count(id, field)
}
pub fn get_relationship_in_range(
&self,
id: &EntityId,
field: &WorkspaceRelationshipField,
offset: usize,
limit: usize,
) -> Result<Vec<EntityId>, RepositoryError> {
self.table
.get_relationship_in_range(id, field, offset, limit)
}
pub fn get_relationships_from_right_ids(
&self,
field: &WorkspaceRelationshipField,
right_ids: &[EntityId],
) -> Result<Vec<(EntityId, Vec<EntityId>)>, RepositoryError> {
self.table
.get_relationships_from_right_ids(field, right_ids)
}
pub fn set_relationship_multi(
&mut self,
event_buffer: &mut EventBuffer,
field: &WorkspaceRelationshipField,
relationships: Vec<(EntityId, Vec<EntityId>)>,
) -> Result<(), RepositoryError> {
let all_right_ids: Vec<EntityId> = relationships
.iter()
.flat_map(|(_, ids)| ids.iter().copied())
.collect();
if !all_right_ids.is_empty() {
match field {
WorkspaceRelationshipField::Entities => {
let child_repo =
repository_factory::write::create_entity_repository(self.transaction)?;
let found = child_repo.get_multi(&all_right_ids)?;
let missing: Vec<_> = all_right_ids
.iter()
.zip(found.iter())
.filter(|(_, entity)| entity.is_none())
.map(|(id, _)| *id)
.collect();
if !missing.is_empty() {
return Err(RepositoryError::MissingRelationshipTarget {
operation: "set_relationship_multi",
ids: missing,
});
}
}
WorkspaceRelationshipField::Features => {
let child_repo =
repository_factory::write::create_feature_repository(self.transaction)?;
let found = child_repo.get_multi(&all_right_ids)?;
let missing: Vec<_> = all_right_ids
.iter()
.zip(found.iter())
.filter(|(_, entity)| entity.is_none())
.map(|(id, _)| *id)
.collect();
if !missing.is_empty() {
return Err(RepositoryError::MissingRelationshipTarget {
operation: "set_relationship_multi",
ids: missing,
});
}
}
WorkspaceRelationshipField::Global => {
let child_repo =
repository_factory::write::create_global_repository(self.transaction)?;
let found = child_repo.get_multi(&all_right_ids)?;
let missing: Vec<_> = all_right_ids
.iter()
.zip(found.iter())
.filter(|(_, entity)| entity.is_none())
.map(|(id, _)| *id)
.collect();
if !missing.is_empty() {
return Err(RepositoryError::MissingRelationshipTarget {
operation: "set_relationship_multi",
ids: missing,
});
}
}
WorkspaceRelationshipField::UserInterface => {
let child_repo = repository_factory::write::create_user_interface_repository(
self.transaction,
)?;
let found = child_repo.get_multi(&all_right_ids)?;
let missing: Vec<_> = all_right_ids
.iter()
.zip(found.iter())
.filter(|(_, entity)| entity.is_none())
.map(|(id, _)| *id)
.collect();
if !missing.is_empty() {
return Err(RepositoryError::MissingRelationshipTarget {
operation: "set_relationship_multi",
ids: missing,
});
}
}
}
}
self.table
.set_relationship_multi(field, relationships.clone())?;
for (left_id, right_ids) in relationships {
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Workspace(EntityEvent::Updated)),
ids: vec![left_id],
data: Some(format!(
"{}:{}",
field,
right_ids
.iter()
.map(|id| id.to_string())
.collect::<Vec<_>>()
.join(",")
)),
});
}
Ok(())
}
pub fn set_relationship(
&mut self,
event_buffer: &mut EventBuffer,
id: &EntityId,
field: &WorkspaceRelationshipField,
right_ids: &[EntityId],
) -> Result<(), RepositoryError> {
if !right_ids.is_empty() {
match field {
WorkspaceRelationshipField::Entities => {
let child_repo =
repository_factory::write::create_entity_repository(self.transaction)?;
let found = child_repo.get_multi(right_ids)?;
let missing: Vec<_> = right_ids
.iter()
.zip(found.iter())
.filter(|(_, entity)| entity.is_none())
.map(|(id, _)| *id)
.collect();
if !missing.is_empty() {
return Err(RepositoryError::MissingRelationshipTarget {
operation: "set_relationship",
ids: missing,
});
}
}
WorkspaceRelationshipField::Features => {
let child_repo =
repository_factory::write::create_feature_repository(self.transaction)?;
let found = child_repo.get_multi(right_ids)?;
let missing: Vec<_> = right_ids
.iter()
.zip(found.iter())
.filter(|(_, entity)| entity.is_none())
.map(|(id, _)| *id)
.collect();
if !missing.is_empty() {
return Err(RepositoryError::MissingRelationshipTarget {
operation: "set_relationship",
ids: missing,
});
}
}
WorkspaceRelationshipField::Global => {
let child_repo =
repository_factory::write::create_global_repository(self.transaction)?;
let found = child_repo.get_multi(right_ids)?;
let missing: Vec<_> = right_ids
.iter()
.zip(found.iter())
.filter(|(_, entity)| entity.is_none())
.map(|(id, _)| *id)
.collect();
if !missing.is_empty() {
return Err(RepositoryError::MissingRelationshipTarget {
operation: "set_relationship",
ids: missing,
});
}
}
WorkspaceRelationshipField::UserInterface => {
let child_repo = repository_factory::write::create_user_interface_repository(
self.transaction,
)?;
let found = child_repo.get_multi(right_ids)?;
let missing: Vec<_> = right_ids
.iter()
.zip(found.iter())
.filter(|(_, entity)| entity.is_none())
.map(|(id, _)| *id)
.collect();
if !missing.is_empty() {
return Err(RepositoryError::MissingRelationshipTarget {
operation: "set_relationship",
ids: missing,
});
}
}
}
}
self.table.set_relationship(id, field, right_ids)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Workspace(EntityEvent::Updated)),
ids: vec![*id],
data: Some(format!(
"{}:{}",
field,
right_ids
.iter()
.map(|id| id.to_string())
.collect::<Vec<_>>()
.join(",")
)),
});
Ok(())
}
pub fn move_relationship_ids(
&mut self,
event_buffer: &mut EventBuffer,
id: &EntityId,
field: &WorkspaceRelationshipField,
ids_to_move: &[EntityId],
new_index: i32,
) -> Result<Vec<EntityId>, RepositoryError> {
let reordered = self
.table
.move_relationship_ids(id, field, ids_to_move, new_index)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Workspace(EntityEvent::Updated)),
ids: vec![*id],
data: Some(format!(
"{}:{}",
field,
reordered
.iter()
.map(|id| id.to_string())
.collect::<Vec<_>>()
.join(",")
)),
});
Ok(reordered)
}
pub fn get_relationships_from_owner(
&self,
owner_id: &EntityId,
) -> Result<Vec<EntityId>, RepositoryError> {
let repo = repository_factory::write::create_root_repository(self.transaction)?;
repo.get_relationship(owner_id, &RootRelationshipField::Workspace)
}
pub fn set_relationships_in_owner(
&mut self,
event_buffer: &mut EventBuffer,
owner_id: &EntityId,
ids: &[EntityId],
) -> Result<(), RepositoryError> {
let mut repo = repository_factory::write::create_root_repository(self.transaction)?;
repo.set_relationship(
event_buffer,
owner_id,
&RootRelationshipField::Workspace,
ids,
)
}
pub fn snapshot(&self, _ids: &[EntityId]) -> Result<EntityTreeSnapshot, RepositoryError> {
let store_snap = self.transaction.snapshot_store();
Ok(EntityTreeSnapshot {
store_snapshot: Some(store_snap),
})
}
pub fn restore(
&mut self,
event_buffer: &mut EventBuffer,
snap: &EntityTreeSnapshot,
) -> Result<(), RepositoryError> {
let store_snap = snap
.store_snapshot
.as_ref()
.ok_or_else(|| RepositoryError::Serialization("missing store snapshot".into()))?;
self.transaction.restore_store(store_snap);
let store = self.transaction.get_store();
let mut emit = |entity: DirectAccessEntity, ids: Vec<EntityId>| {
if !ids.is_empty() {
event_buffer.push(Event {
origin: Origin::DirectAccess(entity),
ids,
data: None,
});
}
};
let workspace_ids: Vec<_> = store.workspaces.read().unwrap().keys().copied().collect();
emit(
DirectAccessEntity::Workspace(EntityEvent::Created),
workspace_ids.clone(),
);
emit(
DirectAccessEntity::Workspace(EntityEvent::Updated),
workspace_ids,
);
{
let child_ids: Vec<_> = store.globals.read().unwrap().keys().copied().collect();
emit(
DirectAccessEntity::Global(EntityEvent::Created),
child_ids.clone(),
);
}
{
let child_ids: Vec<_> = store.entitys.read().unwrap().keys().copied().collect();
emit(
DirectAccessEntity::Entity(EntityEvent::Created),
child_ids.clone(),
);
emit(DirectAccessEntity::Entity(EntityEvent::Updated), child_ids);
}
{
let child_ids: Vec<_> = store.features.read().unwrap().keys().copied().collect();
emit(
DirectAccessEntity::Feature(EntityEvent::Created),
child_ids.clone(),
);
emit(DirectAccessEntity::Feature(EntityEvent::Updated), child_ids);
}
{
let child_ids: Vec<_> = store
.user_interfaces
.read()
.unwrap()
.keys()
.copied()
.collect();
emit(
DirectAccessEntity::UserInterface(EntityEvent::Created),
child_ids.clone(),
);
}
Ok(())
}
}
pub struct WorkspaceRepositoryRO<'a> {
table: Box<dyn WorkspaceTableRO + 'a>,
}
impl<'a> WorkspaceRepositoryRO<'a> {
pub fn new(table: Box<dyn WorkspaceTableRO + 'a>) -> Self {
WorkspaceRepositoryRO { table }
}
pub fn get(&self, id: &EntityId) -> Result<Option<Workspace>, RepositoryError> {
self.table.get(id)
}
pub fn get_multi(&self, ids: &[EntityId]) -> Result<Vec<Option<Workspace>>, RepositoryError> {
self.table.get_multi(ids)
}
pub fn get_all(&self) -> Result<Vec<Workspace>, RepositoryError> {
self.table.get_all()
}
pub fn get_relationship(
&self,
id: &EntityId,
field: &WorkspaceRelationshipField,
) -> Result<Vec<EntityId>, RepositoryError> {
self.table.get_relationship(id, field)
}
pub fn get_relationship_many(
&self,
ids: &[EntityId],
field: &WorkspaceRelationshipField,
) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>, RepositoryError> {
self.table.get_relationship_many(ids, field)
}
pub fn get_relationship_count(
&self,
id: &EntityId,
field: &WorkspaceRelationshipField,
) -> Result<usize, RepositoryError> {
self.table.get_relationship_count(id, field)
}
pub fn get_relationship_in_range(
&self,
id: &EntityId,
field: &WorkspaceRelationshipField,
offset: usize,
limit: usize,
) -> Result<Vec<EntityId>, RepositoryError> {
self.table
.get_relationship_in_range(id, field, offset, limit)
}
pub fn get_relationships_from_right_ids(
&self,
field: &WorkspaceRelationshipField,
right_ids: &[EntityId],
) -> Result<Vec<(EntityId, Vec<EntityId>)>, RepositoryError> {
self.table
.get_relationships_from_right_ids(field, right_ids)
}
}