1use 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 redb_table: Box<dyn BlockTable + 'a>,
127 transaction: &'a Transaction,
128}
129
130impl<'a> BlockRepository<'a> {
131 pub fn new(redb_table: Box<dyn BlockTable + 'a>, transaction: &'a Transaction) -> Self {
132 BlockRepository {
133 redb_table,
134 transaction,
135 }
136 }
137
138 pub fn create_orphan(
139 &mut self,
140 event_buffer: &mut EventBuffer,
141 entity: &Block,
142 ) -> Result<Block, RepositoryError> {
143 let new = self.redb_table.create(entity)?;
144 event_buffer.push(Event {
145 origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Created)),
146 ids: vec![new.id],
147 data: None,
148 });
149 Ok(new)
150 }
151
152 pub fn create_orphan_multi(
153 &mut self,
154 event_buffer: &mut EventBuffer,
155 entities: &[Block],
156 ) -> Result<Vec<Block>, RepositoryError> {
157 let new_entities = self.redb_table.create_multi(entities)?;
158 event_buffer.push(Event {
159 origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Created)),
160 ids: new_entities.iter().map(|e| e.id).collect(),
161 data: None,
162 });
163 Ok(new_entities)
164 }
165 pub fn create(
166 &mut self,
167 event_buffer: &mut EventBuffer,
168 entity: &Block,
169 owner_id: EntityId,
170 index: i32,
171 ) -> Result<Block, RepositoryError> {
172 let new = self.redb_table.create(entity)?;
173 let created_id = new.id;
174
175 let mut relationship_ids = self.get_relationships_from_owner(&owner_id)?;
176 if index >= 0 && (index as usize) < relationship_ids.len() {
178 relationship_ids.insert(index as usize, created_id);
179 } else {
180 relationship_ids.push(created_id);
181 }
182
183 self.set_relationships_in_owner(event_buffer, &owner_id, &relationship_ids)?;
184 event_buffer.push(Event {
185 origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Created)),
186 ids: vec![created_id],
187 data: None,
188 });
189 Ok(new)
190 }
191
192 pub fn create_multi(
193 &mut self,
194 event_buffer: &mut EventBuffer,
195 entities: &[Block],
196 owner_id: EntityId,
197 index: i32,
198 ) -> Result<Vec<Block>, RepositoryError> {
199 let new_entities = self.redb_table.create_multi(entities)?;
200 let created_ids: Vec<EntityId> = new_entities.iter().map(|e| e.id).collect();
201
202 let mut relationship_ids = self.get_relationships_from_owner(&owner_id)?;
203 if index >= 0 && (index as usize) < relationship_ids.len() {
204 for (i, id) in created_ids.iter().enumerate() {
205 relationship_ids.insert(index as usize + i, *id);
206 }
207 } else {
208 relationship_ids.extend(created_ids.iter());
209 }
210
211 self.set_relationships_in_owner(event_buffer, &owner_id, &relationship_ids)?;
212 event_buffer.push(Event {
213 origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Created)),
214 ids: created_ids,
215 data: None,
216 });
217 Ok(new_entities)
218 }
219
220 pub fn get(&self, id: &EntityId) -> Result<Option<Block>, RepositoryError> {
221 self.redb_table.get(id)
222 }
223 pub fn get_multi(&self, ids: &[EntityId]) -> Result<Vec<Option<Block>>, RepositoryError> {
224 self.redb_table.get_multi(ids)
225 }
226 pub fn get_all(&self) -> Result<Vec<Block>, RepositoryError> {
227 self.redb_table.get_all()
228 }
229
230 pub fn update(
231 &mut self,
232 event_buffer: &mut EventBuffer,
233 entity: &Block,
234 ) -> Result<Block, RepositoryError> {
235 let updated = self.redb_table.update(entity)?;
236 event_buffer.push(Event {
237 origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Updated)),
238 ids: vec![updated.id],
239 data: None,
240 });
241 Ok(updated)
242 }
243
244 pub fn update_multi(
245 &mut self,
246 event_buffer: &mut EventBuffer,
247 entities: &[Block],
248 ) -> Result<Vec<Block>, RepositoryError> {
249 let updated = self.redb_table.update_multi(entities)?;
250 event_buffer.push(Event {
251 origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Updated)),
252 ids: updated.iter().map(|e| e.id).collect(),
253 data: None,
254 });
255 Ok(updated)
256 }
257
258 pub fn update_with_relationships(
259 &mut self,
260 event_buffer: &mut EventBuffer,
261 entity: &Block,
262 ) -> Result<Block, RepositoryError> {
263 let updated = self.redb_table.update_with_relationships(entity)?;
264 event_buffer.push(Event {
265 origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Updated)),
266 ids: vec![updated.id],
267 data: None,
268 });
269 Ok(updated)
270 }
271
272 pub fn update_with_relationships_multi(
273 &mut self,
274 event_buffer: &mut EventBuffer,
275 entities: &[Block],
276 ) -> Result<Vec<Block>, RepositoryError> {
277 let updated = self.redb_table.update_with_relationships_multi(entities)?;
278 event_buffer.push(Event {
279 origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Updated)),
280 ids: updated.iter().map(|e| e.id).collect(),
281 data: None,
282 });
283 Ok(updated)
284 }
285
286 pub fn remove(
287 &mut self,
288 event_buffer: &mut EventBuffer,
289 id: &EntityId,
290 ) -> Result<(), RepositoryError> {
291 let entity = match self.redb_table.get(id)? {
292 Some(e) => e,
293 None => return Ok(()),
294 };
295 let elements = entity.elements.clone();
298
299 repository_factory::write::create_inline_element_repository(self.transaction)
302 .remove_multi(event_buffer, &elements)?;
303 let affected_owner_ids: Vec<EntityId> = {
305 let owner_repo = repository_factory::write::create_frame_repository(self.transaction);
306 owner_repo
307 .get_relationships_from_right_ids(&FrameRelationshipField::Blocks, &[*id])?
308 .into_iter()
309 .map(|(owner_id, _)| owner_id)
310 .collect()
311 };
312 let mut owner_rel_before: std::collections::HashMap<EntityId, Vec<EntityId>> =
314 std::collections::HashMap::new();
315 for owner_id in &affected_owner_ids {
316 owner_rel_before.insert(*owner_id, self.get_relationships_from_owner(owner_id)?);
317 }
318
319 self.redb_table.remove(id)?;
321 event_buffer.push(Event {
322 origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Removed)),
323 ids: vec![*id],
324 data: None,
325 });
326 for owner_id in &affected_owner_ids {
328 if let Some(rel_ids) = owner_rel_before.get(owner_id) {
329 let updated: Vec<EntityId> =
330 rel_ids.iter().copied().filter(|rid| *rid != *id).collect();
331 self.set_relationships_in_owner(event_buffer, owner_id, &updated)?;
332 }
333 }
334
335 Ok(())
336 }
337
338 pub fn remove_multi(
339 &mut self,
340 event_buffer: &mut EventBuffer,
341 ids: &[EntityId],
342 ) -> Result<(), RepositoryError> {
343 let entities = self.redb_table.get_multi(ids)?;
344 if entities.is_empty() || entities.iter().all(|e| e.is_none()) {
345 return Ok(());
346 }
347
348 let mut elements_ids: Vec<EntityId> = entities
351 .iter()
352 .flat_map(|entity| entity.as_ref().map(|entity| entity.elements.clone()))
353 .flatten()
354 .collect();
355 elements_ids.sort();
357 elements_ids.dedup();
358
359 repository_factory::write::create_inline_element_repository(self.transaction)
362 .remove_multi(event_buffer, &elements_ids)?;
363 let affected_owner_ids: Vec<EntityId> = {
365 let owner_repo = repository_factory::write::create_frame_repository(self.transaction);
366 owner_repo
367 .get_relationships_from_right_ids(&FrameRelationshipField::Blocks, ids)?
368 .into_iter()
369 .map(|(owner_id, _)| owner_id)
370 .collect()
371 };
372 let mut owner_rel_before: std::collections::HashMap<EntityId, Vec<EntityId>> =
374 std::collections::HashMap::new();
375 for owner_id in &affected_owner_ids {
376 owner_rel_before.insert(*owner_id, self.get_relationships_from_owner(owner_id)?);
377 }
378
379 self.redb_table.remove_multi(ids)?;
380 event_buffer.push(Event {
381 origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Removed)),
382 ids: ids.into(),
383 data: None,
384 });
385 {
387 let removed_set: std::collections::HashSet<EntityId> = ids.iter().copied().collect();
388 for owner_id in &affected_owner_ids {
389 if let Some(rel_ids) = owner_rel_before.get(owner_id) {
390 let updated: Vec<EntityId> = rel_ids
391 .iter()
392 .copied()
393 .filter(|rid| !removed_set.contains(rid))
394 .collect();
395 self.set_relationships_in_owner(event_buffer, owner_id, &updated)?;
396 }
397 }
398 }
399
400 Ok(())
401 }
402 pub fn get_relationship(
403 &self,
404 id: &EntityId,
405 field: &BlockRelationshipField,
406 ) -> Result<Vec<EntityId>, RepositoryError> {
407 self.redb_table.get_relationship(id, field)
408 }
409 pub fn get_relationship_many(
410 &self,
411 ids: &[EntityId],
412 field: &BlockRelationshipField,
413 ) -> Result<std::collections::HashMap<EntityId, Vec<EntityId>>, RepositoryError> {
414 self.redb_table.get_relationship_many(ids, field)
415 }
416 pub fn get_relationship_count(
417 &self,
418 id: &EntityId,
419 field: &BlockRelationshipField,
420 ) -> Result<usize, RepositoryError> {
421 self.redb_table.get_relationship_count(id, field)
422 }
423 pub fn get_relationship_in_range(
424 &self,
425 id: &EntityId,
426 field: &BlockRelationshipField,
427 offset: usize,
428 limit: usize,
429 ) -> Result<Vec<EntityId>, RepositoryError> {
430 self.redb_table
431 .get_relationship_in_range(id, field, offset, limit)
432 }
433 pub fn get_relationships_from_right_ids(
434 &self,
435 field: &BlockRelationshipField,
436 right_ids: &[EntityId],
437 ) -> Result<Vec<(EntityId, Vec<EntityId>)>, RepositoryError> {
438 self.redb_table
439 .get_relationships_from_right_ids(field, right_ids)
440 }
441
442 pub fn set_relationship_multi(
443 &mut self,
444 event_buffer: &mut EventBuffer,
445 field: &BlockRelationshipField,
446 relationships: Vec<(EntityId, Vec<EntityId>)>,
447 ) -> Result<(), RepositoryError> {
448 let all_right_ids: Vec<EntityId> = relationships
450 .iter()
451 .flat_map(|(_, ids)| ids.iter().copied())
452 .collect();
453 if !all_right_ids.is_empty() {
454 match field {
455 BlockRelationshipField::Elements => {
456 let child_repo = repository_factory::write::create_inline_element_repository(
457 self.transaction,
458 );
459 let found = child_repo.get_multi(&all_right_ids)?;
460 let missing: Vec<_> = all_right_ids
461 .iter()
462 .zip(found.iter())
463 .filter(|(_, entity)| entity.is_none())
464 .map(|(id, _)| *id)
465 .collect();
466 if !missing.is_empty() {
467 return Err(RepositoryError::MissingRelationshipTarget {
468 operation: "set_relationship_multi",
469 ids: missing,
470 });
471 }
472 }
473 BlockRelationshipField::List => {
474 let child_repo =
475 repository_factory::write::create_list_repository(self.transaction);
476 let found = child_repo.get_multi(&all_right_ids)?;
477 let missing: Vec<_> = all_right_ids
478 .iter()
479 .zip(found.iter())
480 .filter(|(_, entity)| entity.is_none())
481 .map(|(id, _)| *id)
482 .collect();
483 if !missing.is_empty() {
484 return Err(RepositoryError::MissingRelationshipTarget {
485 operation: "set_relationship_multi",
486 ids: missing,
487 });
488 }
489 }
490 }
491 }
492 self.redb_table
493 .set_relationship_multi(field, relationships.clone())?;
494 for (left_id, right_ids) in relationships {
495 event_buffer.push(Event {
496 origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Updated)),
497 ids: vec![left_id],
498 data: Some(format!(
499 "{}:{}",
500 field,
501 right_ids
502 .iter()
503 .map(|id| id.to_string())
504 .collect::<Vec<_>>()
505 .join(",")
506 )),
507 });
508 }
509 Ok(())
510 }
511
512 pub fn set_relationship(
513 &mut self,
514 event_buffer: &mut EventBuffer,
515 id: &EntityId,
516 field: &BlockRelationshipField,
517 right_ids: &[EntityId],
518 ) -> Result<(), RepositoryError> {
519 if !right_ids.is_empty() {
521 match field {
522 BlockRelationshipField::Elements => {
523 let child_repo = repository_factory::write::create_inline_element_repository(
524 self.transaction,
525 );
526 let found = child_repo.get_multi(right_ids)?;
527 let missing: Vec<_> = right_ids
528 .iter()
529 .zip(found.iter())
530 .filter(|(_, entity)| entity.is_none())
531 .map(|(id, _)| *id)
532 .collect();
533 if !missing.is_empty() {
534 return Err(RepositoryError::MissingRelationshipTarget {
535 operation: "set_relationship",
536 ids: missing,
537 });
538 }
539 }
540 BlockRelationshipField::List => {
541 let child_repo =
542 repository_factory::write::create_list_repository(self.transaction);
543 let found = child_repo.get_multi(right_ids)?;
544 let missing: Vec<_> = right_ids
545 .iter()
546 .zip(found.iter())
547 .filter(|(_, entity)| entity.is_none())
548 .map(|(id, _)| *id)
549 .collect();
550 if !missing.is_empty() {
551 return Err(RepositoryError::MissingRelationshipTarget {
552 operation: "set_relationship",
553 ids: missing,
554 });
555 }
556 }
557 }
558 }
559 self.redb_table.set_relationship(id, field, right_ids)?;
560 event_buffer.push(Event {
561 origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Updated)),
562 ids: vec![*id],
563 data: Some(format!(
564 "{}:{}",
565 field,
566 right_ids
567 .iter()
568 .map(|id| id.to_string())
569 .collect::<Vec<_>>()
570 .join(",")
571 )),
572 });
573 Ok(())
574 }
575
576 pub fn move_relationship_ids(
577 &mut self,
578 event_buffer: &mut EventBuffer,
579 id: &EntityId,
580 field: &BlockRelationshipField,
581 ids_to_move: &[EntityId],
582 new_index: i32,
583 ) -> Result<Vec<EntityId>, RepositoryError> {
584 let reordered = self
585 .redb_table
586 .move_relationship_ids(id, field, ids_to_move, new_index)?;
587 event_buffer.push(Event {
588 origin: Origin::DirectAccess(DirectAccessEntity::Block(EntityEvent::Updated)),
589 ids: vec![*id],
590 data: Some(format!(
591 "{}:{}",
592 field,
593 reordered
594 .iter()
595 .map(|id| id.to_string())
596 .collect::<Vec<_>>()
597 .join(",")
598 )),
599 });
600 Ok(reordered)
601 }
602 pub fn get_relationships_from_owner(
603 &self,
604 owner_id: &EntityId,
605 ) -> Result<Vec<EntityId>, RepositoryError> {
606 let repo = repository_factory::write::create_frame_repository(self.transaction);
607 repo.get_relationship(owner_id, &FrameRelationshipField::Blocks)
608 }
609
610 pub fn set_relationships_in_owner(
611 &mut self,
612 event_buffer: &mut EventBuffer,
613 owner_id: &EntityId,
614 ids: &[EntityId],
615 ) -> Result<(), RepositoryError> {
616 let mut repo = repository_factory::write::create_frame_repository(self.transaction);
617 repo.set_relationship(event_buffer, owner_id, &FrameRelationshipField::Blocks, ids)
618 }
619
620 pub fn snapshot(&self, _ids: &[EntityId]) -> Result<EntityTreeSnapshot, RepositoryError> {
621 let store_snap = self.transaction.snapshot_store();
622 Ok(EntityTreeSnapshot {
623 store_snapshot: Some(store_snap),
624 })
625 }
626
627 pub fn restore(
628 &mut self,
629 event_buffer: &mut EventBuffer,
630 snap: &EntityTreeSnapshot,
631 ) -> Result<(), RepositoryError> {
632 let store_snap = snap
633 .store_snapshot
634 .as_ref()
635 .ok_or_else(|| RepositoryError::Serialization("missing store snapshot".into()))?;
636 self.transaction.restore_store(store_snap);
637
638 let store = self.transaction.get_store();
639
640 let mut emit = |entity: DirectAccessEntity, ids: Vec<EntityId>| {
641 if !ids.is_empty() {
642 event_buffer.push(Event {
643 origin: Origin::DirectAccess(entity),
644 ids,
645 data: None,
646 });
647 }
648 };
649
650 let block_ids: Vec<_> = store.blocks.read().unwrap().keys().copied().collect();
652 emit(
653 DirectAccessEntity::Block(EntityEvent::Created),
654 block_ids.clone(),
655 );
656 emit(DirectAccessEntity::Block(EntityEvent::Updated), block_ids);
657
658 let elem_ids: Vec<_> = store
660 .inline_elements
661 .read()
662 .unwrap()
663 .keys()
664 .copied()
665 .collect();
666 emit(
667 DirectAccessEntity::InlineElement(EntityEvent::Created),
668 elem_ids,
669 );
670
671 Ok(())
672 }
673}
674
675pub struct BlockRepositoryRO<'a> {
676 redb_table: Box<dyn BlockTableRO + 'a>,
677}
678impl<'a> BlockRepositoryRO<'a> {
679 pub fn new(redb_table: Box<dyn BlockTableRO + 'a>) -> Self {
680 BlockRepositoryRO { redb_table }
681 }
682 pub fn get(&self, id: &EntityId) -> Result<Option<Block>, RepositoryError> {
683 self.redb_table.get(id)
684 }
685 pub fn get_multi(&self, ids: &[EntityId]) -> Result<Vec<Option<Block>>, RepositoryError> {
686 self.redb_table.get_multi(ids)
687 }
688 pub fn get_all(&self) -> Result<Vec<Block>, RepositoryError> {
689 self.redb_table.get_all()
690 }
691 pub fn get_relationship(
692 &self,
693 id: &EntityId,
694 field: &BlockRelationshipField,
695 ) -> Result<Vec<EntityId>, RepositoryError> {
696 self.redb_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.redb_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.redb_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.redb_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.redb_table
728 .get_relationships_from_right_ids(field, right_ids)
729 }
730}