Skip to main content

text_document_common/direct_access/table/
table_repository.rs

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