MCPcopy Create free account
hub / github.com/dfinity/orbit / Repository

Interface Repository

libs/orbit-essentials/src/repository.rs:73–135  ·  view source on GitHub ↗

A repository is a generic interface for storing and retrieving data.

Source from the content-addressed store, hash-verified

71
72/// A repository is a generic interface for storing and retrieving data.
73pub trait Repository<Key, Value, Mem>: StableDb<Key, Value, Mem>
74where
75 Key: Eq + std::hash::Hash + Clone + Ord + Storable,
76 Value: Clone + Storable,
77 Mem: Memory,
78{
79 /// Returns the list of records from the repository.
80 fn list(&self) -> Vec<Value> {
81 let mut entries = Vec::with_capacity(self.len());
82
83 Self::with_db(|db| db.iter().for_each(|(_, entry)| entries.push(entry)));
84
85 entries
86 }
87
88 /// Returns whether a record exists in the repository.
89 fn exists(&self, key: &Key) -> bool {
90 Self::with_db(|db| db.contains_key(key))
91 }
92
93 /// Returns the record from the repository if it exists.
94 fn get(&self, key: &Key) -> Option<Value> {
95 Self::with_db(|db| db.get(key))
96 }
97
98 /// Inserts a record into the repository.
99 fn insert(&self, key: Key, value: Value) -> Option<Value> {
100 Self::with_db(|db| db.insert(key, value))
101 }
102
103 /// Removes a record from the repository and returns it if it exists.
104 fn remove(&self, key: &Key) -> Option<Value> {
105 Self::with_db(|db| db.remove(key))
106 }
107
108 /// Returns the number of records stored in the repository.
109 fn len(&self) -> usize {
110 Self::with_db(|db| db.len() as usize)
111 }
112
113 /// Returns whether the repository is empty or not.
114 fn is_empty(&self) -> bool {
115 self.len() == 0
116 }
117
118 fn find_with_filters<'a>(
119 &self,
120 filters: Vec<Box<dyn SelectionFilter<'a, IdType = UUID> + 'a>>,
121 ) -> HashSet<UUID> {
122 let mut found_ids = None;
123
124 for filter in filters {
125 found_ids = Some(filter.apply(found_ids.as_ref()));
126 }
127
128 found_ids.unwrap_or_default()
129 }
130

Callers 27

paginated_itemsFunction · 0.45
newMethod · 0.45
counter_vec_mutMethod · 0.45
counter_mutMethod · 0.45
gauge_vec_mutMethod · 0.45
gauge_mutMethod · 0.45
rebuildMethod · 0.45
to_json_stringMethod · 0.45
detailsMethod · 0.45
remove_counter_vecMethod · 0.45
remove_counterMethod · 0.45

Implementers 15

asset.rscore/station/impl/src/repositories/ass
notification.rscore/station/impl/src/repositories/not
user_group.rscore/station/impl/src/repositories/use
request_evaluation_result.rscore/station/impl/src/repositories/req
request_policy.rscore/station/impl/src/repositories/req
account.rscore/station/impl/src/repositories/acc
request.rscore/station/impl/src/repositories/req
user.rscore/station/impl/src/repositories/use
address_book.rscore/station/impl/src/repositories/add
named_rule.rscore/station/impl/src/repositories/nam
transfer.rscore/station/impl/src/repositories/tra
external_canister.rscore/station/impl/src/repositories/ext

Calls

no outgoing calls

Tested by

no test coverage detected