use std::fmt::Display;
use crate::{
database::hashmap_store::HashMapStoreSnapshot,
database::hashmap_store::{read_or_recover, write_or_recover},
database::transactions::Transaction,
direct_access::repository_factory,
entities::Field,
event::{DirectAccessEntity, EntityEvent, Event, EventBuffer, Origin},
snapshot::EntityTreeSnapshot,
types::EntityId,
};
use crate::direct_access::entity::EntityRelationshipField;
use crate::error::RepositoryError;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum FieldRelationshipField {
Entity,
}
impl Display for FieldRelationshipField {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
pub trait FieldTable {
fn create(&mut self, entity: &Field) -> Result<Field, RepositoryError>;
fn create_multi(&mut self, entities: &[Field]) -> Result<Vec<Field>, RepositoryError>;
fn get(&self, id: &EntityId) -> Result<Option<Field>, RepositoryError>;
fn get_multi(&self, ids: &[EntityId]) -> Result<Vec<Option<Field>>, RepositoryError>;
fn get_all(&self) -> Result<Vec<Field>, RepositoryError>;
fn update(&mut self, entity: &Field) -> Result<Field, RepositoryError>;
fn update_multi(&mut self, entities: &[Field]) -> Result<Vec<Field>, RepositoryError>;
fn update_with_relationships(&mut self, entity: &Field) -> Result<Field, RepositoryError>;
fn update_with_relationships_multi(
&mut self,
entities: &[Field],
) -> Result<Vec<Field>, 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: &FieldRelationshipField,
) -> Result<Vec<EntityId>, RepositoryError>;
fn get_relationship_many(
&self,
ids: &[EntityId],
field: &FieldRelationshipField,
) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>, RepositoryError>;
fn get_relationship_count(
&self,
id: &EntityId,
field: &FieldRelationshipField,
) -> Result<usize, RepositoryError>;
fn get_relationship_in_range(
&self,
id: &EntityId,
field: &FieldRelationshipField,
offset: usize,
limit: usize,
) -> Result<Vec<EntityId>, RepositoryError>;
fn get_relationships_from_right_ids(
&self,
field: &FieldRelationshipField,
right_ids: &[EntityId],
) -> Result<Vec<(EntityId, Vec<EntityId>)>, RepositoryError>;
fn set_relationship_multi(
&mut self,
field: &FieldRelationshipField,
relationships: Vec<(EntityId, Vec<EntityId>)>,
) -> Result<(), RepositoryError>;
fn set_relationship(
&mut self,
id: &EntityId,
field: &FieldRelationshipField,
right_ids: &[EntityId],
) -> Result<(), RepositoryError>;
fn move_relationship_ids(
&mut self,
id: &EntityId,
field: &FieldRelationshipField,
ids_to_move: &[EntityId],
new_index: i32,
) -> Result<Vec<EntityId>, RepositoryError>;
}
pub trait FieldTableRO {
fn get(&self, id: &EntityId) -> Result<Option<Field>, RepositoryError>;
fn get_multi(&self, ids: &[EntityId]) -> Result<Vec<Option<Field>>, RepositoryError>;
fn get_all(&self) -> Result<Vec<Field>, RepositoryError>;
fn get_relationship(
&self,
id: &EntityId,
field: &FieldRelationshipField,
) -> Result<Vec<EntityId>, RepositoryError>;
fn get_relationship_many(
&self,
ids: &[EntityId],
field: &FieldRelationshipField,
) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>, RepositoryError>;
fn get_relationship_count(
&self,
id: &EntityId,
field: &FieldRelationshipField,
) -> Result<usize, RepositoryError>;
fn get_relationship_in_range(
&self,
id: &EntityId,
field: &FieldRelationshipField,
offset: usize,
limit: usize,
) -> Result<Vec<EntityId>, RepositoryError>;
fn get_relationships_from_right_ids(
&self,
field: &FieldRelationshipField,
right_ids: &[EntityId],
) -> Result<Vec<(EntityId, Vec<EntityId>)>, RepositoryError>;
}
pub struct FieldRepository<'a> {
table: Box<dyn FieldTable + 'a>,
transaction: &'a Transaction,
}
impl<'a> FieldRepository<'a> {
pub fn new(table: Box<dyn FieldTable + 'a>, transaction: &'a Transaction) -> Self {
FieldRepository { table, transaction }
}
pub fn create_orphan(
&mut self,
event_buffer: &mut EventBuffer,
entity: &Field,
) -> Result<Field, RepositoryError> {
let new = self.table.create(entity)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Field(EntityEvent::Created)),
ids: vec![new.id],
data: None,
});
Ok(new)
}
pub fn create_orphan_multi(
&mut self,
event_buffer: &mut EventBuffer,
entities: &[Field],
) -> Result<Vec<Field>, RepositoryError> {
let new_entities = self.table.create_multi(entities)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Field(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: &Field,
owner_id: EntityId,
index: i32,
) -> Result<Field, RepositoryError> {
let new = self.table.create(entity)?;
let created_id = new.id;
let mut relationship_ids = self.get_relationships_from_owner(&owner_id)?;
if index >= 0 && (index as usize) < relationship_ids.len() {
relationship_ids.insert(index as usize, created_id);
} else {
relationship_ids.push(created_id);
}
self.set_relationships_in_owner(event_buffer, &owner_id, &relationship_ids)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Field(EntityEvent::Created)),
ids: vec![created_id],
data: None,
});
Ok(new)
}
pub fn create_multi(
&mut self,
event_buffer: &mut EventBuffer,
entities: &[Field],
owner_id: EntityId,
index: i32,
) -> Result<Vec<Field>, 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 index >= 0 && (index as usize) < relationship_ids.len() {
for (i, id) in created_ids.iter().enumerate() {
relationship_ids.insert(index as usize + i, *id);
}
} else {
relationship_ids.extend(created_ids.iter());
}
self.set_relationships_in_owner(event_buffer, &owner_id, &relationship_ids)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Field(EntityEvent::Created)),
ids: created_ids,
data: None,
});
Ok(new_entities)
}
pub fn get(&self, id: &EntityId) -> Result<Option<Field>, RepositoryError> {
self.table.get(id)
}
pub fn get_multi(&self, ids: &[EntityId]) -> Result<Vec<Option<Field>>, RepositoryError> {
self.table.get_multi(ids)
}
pub fn get_all(&self) -> Result<Vec<Field>, RepositoryError> {
self.table.get_all()
}
pub fn update(
&mut self,
event_buffer: &mut EventBuffer,
entity: &Field,
) -> Result<Field, RepositoryError> {
let updated = self.table.update(entity)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Field(EntityEvent::Updated)),
ids: vec![updated.id],
data: None,
});
Ok(updated)
}
pub fn update_multi(
&mut self,
event_buffer: &mut EventBuffer,
entities: &[Field],
) -> Result<Vec<Field>, RepositoryError> {
let updated = self.table.update_multi(entities)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Field(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: &Field,
) -> Result<Field, RepositoryError> {
let updated = self.table.update_with_relationships(entity)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Field(EntityEvent::Updated)),
ids: vec![updated.id],
data: None,
});
Ok(updated)
}
pub fn update_with_relationships_multi(
&mut self,
event_buffer: &mut EventBuffer,
entities: &[Field],
) -> Result<Vec<Field>, RepositoryError> {
let updated = self.table.update_with_relationships_multi(entities)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Field(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 affected_owner_ids: Vec<EntityId> = {
let owner_repo = repository_factory::write::create_entity_repository(self.transaction)?;
owner_repo
.get_relationships_from_right_ids(&EntityRelationshipField::Fields, &[*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::Field(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 affected_owner_ids: Vec<EntityId> = {
let owner_repo = repository_factory::write::create_entity_repository(self.transaction)?;
owner_repo
.get_relationships_from_right_ids(&EntityRelationshipField::Fields, 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::Field(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: &FieldRelationshipField,
) -> Result<Vec<EntityId>, RepositoryError> {
self.table.get_relationship(id, field)
}
pub fn get_relationship_many(
&self,
ids: &[EntityId],
field: &FieldRelationshipField,
) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>, RepositoryError> {
self.table.get_relationship_many(ids, field)
}
pub fn get_relationship_count(
&self,
id: &EntityId,
field: &FieldRelationshipField,
) -> Result<usize, RepositoryError> {
self.table.get_relationship_count(id, field)
}
pub fn get_relationship_in_range(
&self,
id: &EntityId,
field: &FieldRelationshipField,
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: &FieldRelationshipField,
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: &FieldRelationshipField,
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 {
FieldRelationshipField::Entity => {
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,
});
}
}
}
}
self.table
.set_relationship_multi(field, relationships.clone())?;
for (left_id, right_ids) in relationships {
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Field(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: &FieldRelationshipField,
right_ids: &[EntityId],
) -> Result<(), RepositoryError> {
if !right_ids.is_empty() {
match field {
FieldRelationshipField::Entity => {
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,
});
}
}
}
}
self.table.set_relationship(id, field, right_ids)?;
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Field(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: &FieldRelationshipField,
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::Field(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_entity_repository(self.transaction)?;
repo.get_relationship(owner_id, &EntityRelationshipField::Fields)
}
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_entity_repository(self.transaction)?;
repo.set_relationship(
event_buffer,
owner_id,
&EntityRelationshipField::Fields,
ids,
)
}
pub fn snapshot(&self, ids: &[EntityId]) -> Result<EntityTreeSnapshot, RepositoryError> {
let store_snap = self.transaction.snapshot_store();
Ok(EntityTreeSnapshot {
store_snapshot: Some(store_snap),
root_ids: ids.to_vec(),
})
}
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()))?;
let snap_store = store_snap
.downcast_ref::<HashMapStoreSnapshot>()
.ok_or_else(|| RepositoryError::Serialization("snapshot type mismatch".into()))?;
let mut visited = std::collections::HashSet::new();
self.restore_subtree(event_buffer, snap_store, &snap.root_ids, &mut visited)?;
self.reconcile_backref_entity_fields(event_buffer, snap_store, &snap.root_ids)?;
Ok(())
}
pub(crate) fn restore_subtree(
&self,
event_buffer: &mut EventBuffer,
snap: &HashMapStoreSnapshot,
ids: &[EntityId],
visited: &mut std::collections::HashSet<(&'static str, EntityId)>,
) -> Result<(), RepositoryError> {
let ids: Vec<EntityId> = ids
.iter()
.copied()
.filter(|id| visited.insert(("field", *id)))
.collect();
if ids.is_empty() {
return Ok(());
}
let store = self.transaction.get_store();
let mut to_create: Vec<EntityId> = Vec::new(); let mut to_update: Vec<EntityId> = Vec::new(); let mut to_delete: Vec<EntityId> = Vec::new(); {
let live = read_or_recover(&store.fields);
for id in &ids {
match (snap.fields.contains_key(id), live.contains_key(id)) {
(true, false) => to_create.push(*id),
(true, true) => to_update.push(*id),
(false, true) => to_delete.push(*id),
(false, false) => {}
}
}
}
{
let mut live = write_or_recover(&store.fields);
for id in to_create.iter().chain(to_update.iter()) {
if let Some(row) = snap.fields.get(id) {
live.insert(*id, row.clone());
}
}
for id in &to_delete {
live.remove(id);
}
}
{
let mut live_jn = write_or_recover(&store.jn_entity_from_field_entity);
for id in to_create.iter().chain(to_update.iter()) {
match snap.jn_entity_from_field_entity.get(id) {
Some(v) => {
live_jn.insert(*id, v.clone());
}
None => {
live_jn.remove(id);
}
}
}
for id in &to_delete {
live_jn.remove(id);
}
}
self.reconcile_backref_file_field(event_buffer, snap, &ids)?;
if !to_create.is_empty() {
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Field(EntityEvent::Created)),
ids: to_create.clone(),
data: None,
});
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Field(EntityEvent::Updated)),
ids: to_create.clone(),
data: None,
});
}
if !to_update.is_empty() {
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Field(EntityEvent::Updated)),
ids: to_update.clone(),
data: None,
});
}
if !to_delete.is_empty() {
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Field(EntityEvent::Removed)),
ids: to_delete.clone(),
data: None,
});
}
Ok(())
}
fn reconcile_backref_file_field(
&self,
event_buffer: &mut EventBuffer,
snap: &HashMapStoreSnapshot,
scope_ids: &[EntityId],
) -> Result<(), RepositoryError> {
let scope: std::collections::HashSet<EntityId> = scope_ids.iter().copied().collect();
if scope.is_empty() {
return Ok(());
}
let store = self.transaction.get_store();
let mut left_keys: std::collections::HashSet<EntityId> = std::collections::HashSet::new();
for (left, rights) in snap.jn_field_from_file_field.iter() {
if rights.iter().any(|rid| scope.contains(rid)) {
left_keys.insert(*left);
}
}
{
let live_jn = read_or_recover(&store.jn_field_from_file_field);
for (left, rights) in live_jn.iter() {
if rights.iter().any(|rid| scope.contains(rid)) {
left_keys.insert(*left);
}
}
}
for left in left_keys {
let snap_list: Vec<EntityId> = snap
.jn_field_from_file_field
.get(&left)
.cloned()
.unwrap_or_default();
let new_list = {
let live_jn = read_or_recover(&store.jn_field_from_file_field);
let live_list: Vec<EntityId> = live_jn.get(&left).cloned().unwrap_or_default();
let reconciled = crate::database::hashmap_store::reconcile_backref_list(
&live_list, &snap_list, &scope,
);
if reconciled == live_list {
None
} else {
Some(reconciled)
}
};
if let Some(reconciled) = new_list {
write_or_recover(&store.jn_field_from_file_field).insert(left, reconciled);
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::File(EntityEvent::Updated)),
ids: vec![left],
data: None,
});
}
}
Ok(())
}
fn reconcile_backref_entity_fields(
&self,
event_buffer: &mut EventBuffer,
snap: &HashMapStoreSnapshot,
scope_ids: &[EntityId],
) -> Result<(), RepositoryError> {
let scope: std::collections::HashSet<EntityId> = scope_ids.iter().copied().collect();
if scope.is_empty() {
return Ok(());
}
let store = self.transaction.get_store();
let mut left_keys: std::collections::HashSet<EntityId> = std::collections::HashSet::new();
for (left, rights) in snap.jn_field_from_entity_fields.iter() {
if rights.iter().any(|rid| scope.contains(rid)) {
left_keys.insert(*left);
}
}
{
let live_jn = read_or_recover(&store.jn_field_from_entity_fields);
for (left, rights) in live_jn.iter() {
if rights.iter().any(|rid| scope.contains(rid)) {
left_keys.insert(*left);
}
}
}
for left in left_keys {
let snap_list: Vec<EntityId> = snap
.jn_field_from_entity_fields
.get(&left)
.cloned()
.unwrap_or_default();
let new_list = {
let live_jn = read_or_recover(&store.jn_field_from_entity_fields);
let live_list: Vec<EntityId> = live_jn.get(&left).cloned().unwrap_or_default();
let reconciled = crate::database::hashmap_store::reconcile_backref_list(
&live_list, &snap_list, &scope,
);
if reconciled == live_list {
None
} else {
Some(reconciled)
}
};
if let Some(reconciled) = new_list {
write_or_recover(&store.jn_field_from_entity_fields).insert(left, reconciled);
event_buffer.push(Event {
origin: Origin::DirectAccess(DirectAccessEntity::Entity(EntityEvent::Updated)),
ids: vec![left],
data: None,
});
}
}
Ok(())
}
}
pub struct FieldRepositoryRO<'a> {
table: Box<dyn FieldTableRO + 'a>,
}
impl<'a> FieldRepositoryRO<'a> {
pub fn new(table: Box<dyn FieldTableRO + 'a>) -> Self {
FieldRepositoryRO { table }
}
pub fn get(&self, id: &EntityId) -> Result<Option<Field>, RepositoryError> {
self.table.get(id)
}
pub fn get_multi(&self, ids: &[EntityId]) -> Result<Vec<Option<Field>>, RepositoryError> {
self.table.get_multi(ids)
}
pub fn get_all(&self) -> Result<Vec<Field>, RepositoryError> {
self.table.get_all()
}
pub fn get_relationship(
&self,
id: &EntityId,
field: &FieldRelationshipField,
) -> Result<Vec<EntityId>, RepositoryError> {
self.table.get_relationship(id, field)
}
pub fn get_relationship_many(
&self,
ids: &[EntityId],
field: &FieldRelationshipField,
) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>, RepositoryError> {
self.table.get_relationship_many(ids, field)
}
pub fn get_relationship_count(
&self,
id: &EntityId,
field: &FieldRelationshipField,
) -> Result<usize, RepositoryError> {
self.table.get_relationship_count(id, field)
}
pub fn get_relationship_in_range(
&self,
id: &EntityId,
field: &FieldRelationshipField,
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: &FieldRelationshipField,
right_ids: &[EntityId],
) -> Result<Vec<(EntityId, Vec<EntityId>)>, RepositoryError> {
self.table
.get_relationships_from_right_ids(field, right_ids)
}
}