Skip to main content

common/direct_access/block/
block_repository.rs

1// Generated by Qleany v1.7.3 from common_entity_repository.tera
2
3use std::fmt::Display;
4
5use crate::{
6    database::transactions::Transaction,
7    direct_access::repository_factory,
8    entities::Block,
9    event::{DirectAccessEntity, EntityEvent, Event, EventBuffer, Origin},
10    snapshot::EntityTreeSnapshot,
11    types::EntityId,
12};
13
14use crate::direct_access::frame::FrameRelationshipField;
15use crate::error::RepositoryError;
16use serde::{Deserialize, Serialize};
17
18#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
19pub enum BlockRelationshipField {
20    Elements,
21    List,
22}
23
24impl Display for BlockRelationshipField {
25    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
26        write!(f, "{:?}", self)
27    }
28}
29
30pub trait BlockTable {
31    fn create(&mut self, entity: &Block) -> Result<Block, RepositoryError>;
32    fn create_multi(&mut self, entities: &[Block]) -> Result<Vec<Block>, RepositoryError>;
33    fn get(&self, id: &EntityId) -> Result<Option<Block>, RepositoryError>;
34    fn get_multi(&self, ids: &[EntityId]) -> Result<Vec<Option<Block>>, RepositoryError>;
35    fn get_all(&self) -> Result<Vec<Block>, RepositoryError>;
36    fn update(&mut self, entity: &Block) -> Result<Block, RepositoryError>;
37    fn update_multi(&mut self, entities: &[Block]) -> Result<Vec<Block>, RepositoryError>;
38    fn update_with_relationships(&mut self, entity: &Block) -> Result<Block, RepositoryError>;
39    fn update_with_relationships_multi(
40        &mut self,
41        entities: &[Block],
42    ) -> Result<Vec<Block>, RepositoryError>;
43    fn remove(&mut self, id: &EntityId) -> Result<(), RepositoryError>;
44    fn remove_multi(&mut self, ids: &[EntityId]) -> Result<(), RepositoryError>;
45    fn get_relationship(
46        &self,
47        id: &EntityId,
48        field: &BlockRelationshipField,
49    ) -> Result<Vec<EntityId>, RepositoryError>;
50    fn get_relationship_many(
51        &self,
52        ids: &[EntityId],
53        field: &BlockRelationshipField,
54    ) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>, RepositoryError>;
55    fn get_relationship_count(
56        &self,
57        id: &EntityId,
58        field: &BlockRelationshipField,
59    ) -> Result<usize, RepositoryError>;
60    fn get_relationship_in_range(
61        &self,
62        id: &EntityId,
63        field: &BlockRelationshipField,
64        offset: usize,
65        limit: usize,
66    ) -> Result<Vec<EntityId>, RepositoryError>;
67    fn get_relationships_from_right_ids(
68        &self,
69        field: &BlockRelationshipField,
70        right_ids: &[EntityId],
71    ) -> Result<Vec<(EntityId, Vec<EntityId>)>, RepositoryError>;
72    fn set_relationship_multi(
73        &mut self,
74        field: &BlockRelationshipField,
75        relationships: Vec<(EntityId, Vec<EntityId>)>,
76    ) -> Result<(), RepositoryError>;
77    fn set_relationship(
78        &mut self,
79        id: &EntityId,
80        field: &BlockRelationshipField,
81        right_ids: &[EntityId],
82    ) -> Result<(), RepositoryError>;
83    fn move_relationship_ids(
84        &mut self,
85        id: &EntityId,
86        field: &BlockRelationshipField,
87        ids_to_move: &[EntityId],
88        new_index: i32,
89    ) -> Result<Vec<EntityId>, RepositoryError>;
90}
91
92pub trait BlockTableRO {
93    fn get(&self, id: &EntityId) -> Result<Option<Block>, RepositoryError>;
94    fn get_multi(&self, ids: &[EntityId]) -> Result<Vec<Option<Block>>, RepositoryError>;
95    fn get_all(&self) -> Result<Vec<Block>, RepositoryError>;
96    fn get_relationship(
97        &self,
98        id: &EntityId,
99        field: &BlockRelationshipField,
100    ) -> Result<Vec<EntityId>, RepositoryError>;
101    fn get_relationship_many(
102        &self,
103        ids: &[EntityId],
104        field: &BlockRelationshipField,
105    ) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>, RepositoryError>;
106    fn get_relationship_count(
107        &self,
108        id: &EntityId,
109        field: &BlockRelationshipField,
110    ) -> Result<usize, RepositoryError>;
111    fn get_relationship_in_range(
112        &self,
113        id: &EntityId,
114        field: &BlockRelationshipField,
115        offset: usize,
116        limit: usize,
117    ) -> Result<Vec<EntityId>, RepositoryError>;
118    fn get_relationships_from_right_ids(
119        &self,
120        field: &BlockRelationshipField,
121        right_ids: &[EntityId],
122    ) -> Result<Vec<(EntityId, Vec<EntityId>)>, RepositoryError>;
123}
124
125pub struct BlockRepository<'a> {
126    table: Box<dyn BlockTable + 'a>,
127    transaction: &'a Transaction,
128}
129
130impl<'a> BlockRepository<'a> {
131    pub fn new(table: Box<dyn BlockTable + 'a>, transaction: &'a Transaction) -> Self {
132        BlockRepository { table, transaction }
133    }
134
135    pub fn create_orphan(
136        &mut self,
137        event_buffer: &mut EventBuffer,
138        entity: &Block,
139    ) -> Result<Block, RepositoryError> {
140        let new = self.table.create(entity)?;
141        event_buffer.push(Event {
142            origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Created)),
143            ids: vec![new.id],
144            data: None,
145        });
146        Ok(new)
147    }
148
149    pub fn create_orphan_multi(
150        &mut self,
151        event_buffer: &mut EventBuffer,
152        entities: &[Block],
153    ) -> Result<Vec<Block>, RepositoryError> {
154        let new_entities = self.table.create_multi(entities)?;
155        event_buffer.push(Event {
156            origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Created)),
157            ids: new_entities.iter().map(|e| e.id).collect(),
158            data: None,
159        });
160        Ok(new_entities)
161    }
162    pub fn create(
163        &mut self,
164        event_buffer: &mut EventBuffer,
165        entity: &Block,
166        owner_id: EntityId,
167        index: i32,
168    ) -> Result<Block, RepositoryError> {
169        let new = self.table.create(entity)?;
170        let created_id = new.id;
171
172        let mut relationship_ids = self.get_relationships_from_owner(&owner_id)?;
173        // Insert at index
174        if index >= 0 && (index as usize) < relationship_ids.len() {
175            relationship_ids.insert(index as usize, created_id);
176        } else {
177            relationship_ids.push(created_id);
178        }
179
180        self.set_relationships_in_owner(event_buffer, &owner_id, &relationship_ids)?;
181        event_buffer.push(Event {
182            origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Created)),
183            ids: vec![created_id],
184            data: None,
185        });
186        Ok(new)
187    }
188
189    pub fn create_multi(
190        &mut self,
191        event_buffer: &mut EventBuffer,
192        entities: &[Block],
193        owner_id: EntityId,
194        index: i32,
195    ) -> Result<Vec<Block>, RepositoryError> {
196        let new_entities = self.table.create_multi(entities)?;
197        let created_ids: Vec<EntityId> = new_entities.iter().map(|e| e.id).collect();
198
199        let mut relationship_ids = self.get_relationships_from_owner(&owner_id)?;
200        if index >= 0 && (index as usize) < relationship_ids.len() {
201            for (i, id) in created_ids.iter().enumerate() {
202                relationship_ids.insert(index as usize + i, *id);
203            }
204        } else {
205            relationship_ids.extend(created_ids.iter());
206        }
207
208        self.set_relationships_in_owner(event_buffer, &owner_id, &relationship_ids)?;
209        event_buffer.push(Event {
210            origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Created)),
211            ids: created_ids,
212            data: None,
213        });
214        Ok(new_entities)
215    }
216
217    pub fn get(&self, id: &EntityId) -> Result<Option<Block>, RepositoryError> {
218        self.table.get(id)
219    }
220    pub fn get_multi(&self, ids: &[EntityId]) -> Result<Vec<Option<Block>>, RepositoryError> {
221        self.table.get_multi(ids)
222    }
223    pub fn get_all(&self) -> Result<Vec<Block>, RepositoryError> {
224        self.table.get_all()
225    }
226
227    pub fn update(
228        &mut self,
229        event_buffer: &mut EventBuffer,
230        entity: &Block,
231    ) -> Result<Block, RepositoryError> {
232        let updated = self.table.update(entity)?;
233        event_buffer.push(Event {
234            origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Updated)),
235            ids: vec![updated.id],
236            data: None,
237        });
238        Ok(updated)
239    }
240
241    pub fn update_multi(
242        &mut self,
243        event_buffer: &mut EventBuffer,
244        entities: &[Block],
245    ) -> Result<Vec<Block>, RepositoryError> {
246        let updated = self.table.update_multi(entities)?;
247        event_buffer.push(Event {
248            origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Updated)),
249            ids: updated.iter().map(|e| e.id).collect(),
250            data: None,
251        });
252        Ok(updated)
253    }
254
255    pub fn update_with_relationships(
256        &mut self,
257        event_buffer: &mut EventBuffer,
258        entity: &Block,
259    ) -> Result<Block, RepositoryError> {
260        let updated = self.table.update_with_relationships(entity)?;
261        event_buffer.push(Event {
262            origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Updated)),
263            ids: vec![updated.id],
264            data: None,
265        });
266        Ok(updated)
267    }
268
269    pub fn update_with_relationships_multi(
270        &mut self,
271        event_buffer: &mut EventBuffer,
272        entities: &[Block],
273    ) -> Result<Vec<Block>, RepositoryError> {
274        let updated = self.table.update_with_relationships_multi(entities)?;
275        event_buffer.push(Event {
276            origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Updated)),
277            ids: updated.iter().map(|e| e.id).collect(),
278            data: None,
279        });
280        Ok(updated)
281    }
282
283    pub fn remove(
284        &mut self,
285        event_buffer: &mut EventBuffer,
286        id: &EntityId,
287    ) -> Result<(), RepositoryError> {
288        let entity = match self.table.get(id)? {
289            Some(e) => e,
290            None => return Ok(()),
291        };
292        // get all strong forward relationship fields
293
294        let elements = entity.elements.clone();
295
296        // remove all strong relationships, initiating a cascade remove
297
298        repository_factory::write::create_inline_element_repository(self.transaction)?
299            .remove_multi(event_buffer, &elements)?;
300        // Before removal, find which owner(s) reference this entity
301        let affected_owner_ids: Vec<EntityId> = {
302            let owner_repo = repository_factory::write::create_frame_repository(self.transaction)?;
303            owner_repo
304                .get_relationships_from_right_ids(&FrameRelationshipField::Blocks, &[*id])?
305                .into_iter()
306                .map(|(owner_id, _)| owner_id)
307                .collect()
308        };
309        // Save each owner's current relationship IDs (properly ordered via get_relationships_from_owner)
310        let mut owner_rel_before: std::collections::HashMap<EntityId, Vec<EntityId>> =
311            std::collections::HashMap::new();
312        for owner_id in &affected_owner_ids {
313            owner_rel_before.insert(*owner_id, self.get_relationships_from_owner(owner_id)?);
314        }
315
316        // remove entity
317        self.table.remove(id)?;
318        event_buffer.push(Event {
319            origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Removed)),
320            ids: vec![*id],
321            data: None,
322        });
323        // Update each affected owner's relationship to exclude removed ID (emits Updated event)
324        for owner_id in &affected_owner_ids {
325            if let Some(rel_ids) = owner_rel_before.get(owner_id) {
326                let updated: Vec<EntityId> =
327                    rel_ids.iter().copied().filter(|rid| *rid != *id).collect();
328                self.set_relationships_in_owner(event_buffer, owner_id, &updated)?;
329            }
330        }
331
332        Ok(())
333    }
334
335    pub fn remove_multi(
336        &mut self,
337        event_buffer: &mut EventBuffer,
338        ids: &[EntityId],
339    ) -> Result<(), RepositoryError> {
340        let entities = self.table.get_multi(ids)?;
341        if entities.is_empty() || entities.iter().all(|e| e.is_none()) {
342            return Ok(());
343        }
344
345        // get all strong forward relationship fields
346
347        let mut elements_ids: Vec<EntityId> = entities
348            .iter()
349            .flat_map(|entity| entity.as_ref().map(|entity| entity.elements.clone()))
350            .flatten()
351            .collect();
352        // remove duplicates
353        elements_ids.sort();
354        elements_ids.dedup();
355
356        // remove all strong relationships, initiating a cascade remove
357
358        repository_factory::write::create_inline_element_repository(self.transaction)?
359            .remove_multi(event_buffer, &elements_ids)?;
360        // Before removal, find which owner(s) reference these entities
361        let affected_owner_ids: Vec<EntityId> = {
362            let owner_repo = repository_factory::write::create_frame_repository(self.transaction)?;
363            owner_repo
364                .get_relationships_from_right_ids(&FrameRelationshipField::Blocks, ids)?
365                .into_iter()
366                .map(|(owner_id, _)| owner_id)
367                .collect()
368        };
369        // Save each owner's current relationship IDs (properly ordered via get_relationships_from_owner)
370        let mut owner_rel_before: std::collections::HashMap<EntityId, Vec<EntityId>> =
371            std::collections::HashMap::new();
372        for owner_id in &affected_owner_ids {
373            owner_rel_before.insert(*owner_id, self.get_relationships_from_owner(owner_id)?);
374        }
375
376        self.table.remove_multi(ids)?;
377        event_buffer.push(Event {
378            origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Removed)),
379            ids: ids.into(),
380            data: None,
381        });
382        // Update each affected owner's relationship to exclude removed IDs (emits Updated event)
383        {
384            let removed_set: std::collections::HashSet<EntityId> = ids.iter().copied().collect();
385            for owner_id in &affected_owner_ids {
386                if let Some(rel_ids) = owner_rel_before.get(owner_id) {
387                    let updated: Vec<EntityId> = rel_ids
388                        .iter()
389                        .copied()
390                        .filter(|rid| !removed_set.contains(rid))
391                        .collect();
392                    self.set_relationships_in_owner(event_buffer, owner_id, &updated)?;
393                }
394            }
395        }
396
397        Ok(())
398    }
399    pub fn get_relationship(
400        &self,
401        id: &EntityId,
402        field: &BlockRelationshipField,
403    ) -> Result<Vec<EntityId>, RepositoryError> {
404        self.table.get_relationship(id, field)
405    }
406    pub fn get_relationship_many(
407        &self,
408        ids: &[EntityId],
409        field: &BlockRelationshipField,
410    ) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>, RepositoryError> {
411        self.table.get_relationship_many(ids, field)
412    }
413    pub fn get_relationship_count(
414        &self,
415        id: &EntityId,
416        field: &BlockRelationshipField,
417    ) -> Result<usize, RepositoryError> {
418        self.table.get_relationship_count(id, field)
419    }
420    pub fn get_relationship_in_range(
421        &self,
422        id: &EntityId,
423        field: &BlockRelationshipField,
424        offset: usize,
425        limit: usize,
426    ) -> Result<Vec<EntityId>, RepositoryError> {
427        self.table
428            .get_relationship_in_range(id, field, offset, limit)
429    }
430    pub fn get_relationships_from_right_ids(
431        &self,
432        field: &BlockRelationshipField,
433        right_ids: &[EntityId],
434    ) -> Result<Vec<(EntityId, Vec<EntityId>)>, RepositoryError> {
435        self.table
436            .get_relationships_from_right_ids(field, right_ids)
437    }
438
439    pub fn set_relationship_multi(
440        &mut self,
441        event_buffer: &mut EventBuffer,
442        field: &BlockRelationshipField,
443        relationships: Vec<(EntityId, Vec<EntityId>)>,
444    ) -> Result<(), RepositoryError> {
445        // Validate that all right_ids exist
446        let all_right_ids: Vec<EntityId> = relationships
447            .iter()
448            .flat_map(|(_, ids)| ids.iter().copied())
449            .collect();
450        if !all_right_ids.is_empty() {
451            match field {
452                BlockRelationshipField::Elements => {
453                    let child_repo = repository_factory::write::create_inline_element_repository(
454                        self.transaction,
455                    )?;
456                    let found = child_repo.get_multi(&all_right_ids)?;
457                    let missing: Vec<_> = all_right_ids
458                        .iter()
459                        .zip(found.iter())
460                        .filter(|(_, entity)| entity.is_none())
461                        .map(|(id, _)| *id)
462                        .collect();
463                    if !missing.is_empty() {
464                        return Err(RepositoryError::MissingRelationshipTarget {
465                            operation: "set_relationship_multi",
466                            ids: missing,
467                        });
468                    }
469                }
470                BlockRelationshipField::List => {
471                    let child_repo =
472                        repository_factory::write::create_list_repository(self.transaction)?;
473                    let found = child_repo.get_multi(&all_right_ids)?;
474                    let missing: Vec<_> = all_right_ids
475                        .iter()
476                        .zip(found.iter())
477                        .filter(|(_, entity)| entity.is_none())
478                        .map(|(id, _)| *id)
479                        .collect();
480                    if !missing.is_empty() {
481                        return Err(RepositoryError::MissingRelationshipTarget {
482                            operation: "set_relationship_multi",
483                            ids: missing,
484                        });
485                    }
486                }
487            }
488        }
489        self.table
490            .set_relationship_multi(field, relationships.clone())?;
491        for (left_id, right_ids) in relationships {
492            event_buffer.push(Event {
493                origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Updated)),
494                ids: vec![left_id],
495                data: Some(format!(
496                    "{}:{}",
497                    field,
498                    right_ids
499                        .iter()
500                        .map(|id| id.to_string())
501                        .collect::<Vec<_>>()
502                        .join(",")
503                )),
504            });
505        }
506        Ok(())
507    }
508
509    pub fn set_relationship(
510        &mut self,
511        event_buffer: &mut EventBuffer,
512        id: &EntityId,
513        field: &BlockRelationshipField,
514        right_ids: &[EntityId],
515    ) -> Result<(), RepositoryError> {
516        // Validate that all right_ids exist
517        if !right_ids.is_empty() {
518            match field {
519                BlockRelationshipField::Elements => {
520                    let child_repo = repository_factory::write::create_inline_element_repository(
521                        self.transaction,
522                    )?;
523                    let found = child_repo.get_multi(right_ids)?;
524                    let missing: Vec<_> = right_ids
525                        .iter()
526                        .zip(found.iter())
527                        .filter(|(_, entity)| entity.is_none())
528                        .map(|(id, _)| *id)
529                        .collect();
530                    if !missing.is_empty() {
531                        return Err(RepositoryError::MissingRelationshipTarget {
532                            operation: "set_relationship",
533                            ids: missing,
534                        });
535                    }
536                }
537                BlockRelationshipField::List => {
538                    let child_repo =
539                        repository_factory::write::create_list_repository(self.transaction)?;
540                    let found = child_repo.get_multi(right_ids)?;
541                    let missing: Vec<_> = right_ids
542                        .iter()
543                        .zip(found.iter())
544                        .filter(|(_, entity)| entity.is_none())
545                        .map(|(id, _)| *id)
546                        .collect();
547                    if !missing.is_empty() {
548                        return Err(RepositoryError::MissingRelationshipTarget {
549                            operation: "set_relationship",
550                            ids: missing,
551                        });
552                    }
553                }
554            }
555        }
556        self.table.set_relationship(id, field, right_ids)?;
557        event_buffer.push(Event {
558            origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Updated)),
559            ids: vec![*id],
560            data: Some(format!(
561                "{}:{}",
562                field,
563                right_ids
564                    .iter()
565                    .map(|id| id.to_string())
566                    .collect::<Vec<_>>()
567                    .join(",")
568            )),
569        });
570        Ok(())
571    }
572
573    pub fn move_relationship_ids(
574        &mut self,
575        event_buffer: &mut EventBuffer,
576        id: &EntityId,
577        field: &BlockRelationshipField,
578        ids_to_move: &[EntityId],
579        new_index: i32,
580    ) -> Result<Vec<EntityId>, RepositoryError> {
581        let reordered = self
582            .table
583            .move_relationship_ids(id, field, ids_to_move, new_index)?;
584        event_buffer.push(Event {
585            origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Updated)),
586            ids: vec![*id],
587            data: Some(format!(
588                "{}:{}",
589                field,
590                reordered
591                    .iter()
592                    .map(|id| id.to_string())
593                    .collect::<Vec<_>>()
594                    .join(",")
595            )),
596        });
597        Ok(reordered)
598    }
599    pub fn get_relationships_from_owner(
600        &self,
601        owner_id: &EntityId,
602    ) -> Result<Vec<EntityId>, RepositoryError> {
603        let repo = repository_factory::write::create_frame_repository(self.transaction)?;
604        repo.get_relationship(owner_id, &FrameRelationshipField::Blocks)
605    }
606
607    pub fn set_relationships_in_owner(
608        &mut self,
609        event_buffer: &mut EventBuffer,
610        owner_id: &EntityId,
611        ids: &[EntityId],
612    ) -> Result<(), RepositoryError> {
613        let mut repo = repository_factory::write::create_frame_repository(self.transaction)?;
614        repo.set_relationship(event_buffer, owner_id, &FrameRelationshipField::Blocks, ids)
615    }
616
617    pub fn snapshot(&self, _ids: &[EntityId]) -> Result<EntityTreeSnapshot, RepositoryError> {
618        let store_snap = self.transaction.snapshot_store();
619        Ok(EntityTreeSnapshot {
620            store_snapshot: Some(store_snap),
621        })
622    }
623
624    pub fn restore(
625        &mut self,
626        event_buffer: &mut EventBuffer,
627        snap: &EntityTreeSnapshot,
628    ) -> Result<(), RepositoryError> {
629        let store_snap = snap
630            .store_snapshot
631            .as_ref()
632            .ok_or_else(|| RepositoryError::Serialization("missing store snapshot".into()))?;
633        self.transaction.restore_store(store_snap);
634
635        let store = self.transaction.get_store();
636
637        let mut emit = |entity: DirectAccessEntity, ids: Vec<EntityId>| {
638            if !ids.is_empty() {
639                event_buffer.push(Event {
640                    origin: Origin::DirectAccess(entity),
641                    ids,
642                    data: None,
643                });
644            }
645        };
646
647        // Emit Created events for this entity
648        let block_ids: Vec<_> = store.blocks.read().unwrap().keys().copied().collect();
649        emit(
650            DirectAccessEntity::Block(EntityEvent::Created),
651            block_ids.clone(),
652        );
653        emit(DirectAccessEntity::Block(EntityEvent::Updated), block_ids);
654
655        // Emit Created events for strong children
656
657        {
658            let child_ids: Vec<_> = store
659                .inline_elements
660                .read()
661                .unwrap()
662                .keys()
663                .copied()
664                .collect();
665            emit(
666                DirectAccessEntity::InlineElement(EntityEvent::Created),
667                child_ids.clone(),
668            );
669        }
670
671        Ok(())
672    }
673}
674
675pub struct BlockRepositoryRO<'a> {
676    table: Box<dyn BlockTableRO + 'a>,
677}
678impl<'a> BlockRepositoryRO<'a> {
679    pub fn new(table: Box<dyn BlockTableRO + 'a>) -> Self {
680        BlockRepositoryRO { table }
681    }
682    pub fn get(&self, id: &EntityId) -> Result<Option<Block>, RepositoryError> {
683        self.table.get(id)
684    }
685    pub fn get_multi(&self, ids: &[EntityId]) -> Result<Vec<Option<Block>>, RepositoryError> {
686        self.table.get_multi(ids)
687    }
688    pub fn get_all(&self) -> Result<Vec<Block>, RepositoryError> {
689        self.table.get_all()
690    }
691    pub fn get_relationship(
692        &self,
693        id: &EntityId,
694        field: &BlockRelationshipField,
695    ) -> Result<Vec<EntityId>, RepositoryError> {
696        self.table.get_relationship(id, field)
697    }
698    pub fn get_relationship_many(
699        &self,
700        ids: &[EntityId],
701        field: &BlockRelationshipField,
702    ) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>, RepositoryError> {
703        self.table.get_relationship_many(ids, field)
704    }
705    pub fn get_relationship_count(
706        &self,
707        id: &EntityId,
708        field: &BlockRelationshipField,
709    ) -> Result<usize, RepositoryError> {
710        self.table.get_relationship_count(id, field)
711    }
712    pub fn get_relationship_in_range(
713        &self,
714        id: &EntityId,
715        field: &BlockRelationshipField,
716        offset: usize,
717        limit: usize,
718    ) -> Result<Vec<EntityId>, RepositoryError> {
719        self.table
720            .get_relationship_in_range(id, field, offset, limit)
721    }
722    pub fn get_relationships_from_right_ids(
723        &self,
724        field: &BlockRelationshipField,
725        right_ids: &[EntityId],
726    ) -> Result<Vec<(EntityId, Vec<EntityId>)>, RepositoryError> {
727        self.table
728            .get_relationships_from_right_ids(field, right_ids)
729    }
730}