Skip to content

Commit c0e9492

Browse files
committed
feat: add Store class for managing data with identifier-based retrieval
1 parent 4ac0caf commit c0e9492

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/store/data_store.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from abc import ABC
2+
from typing import Any, List
3+
4+
5+
class Store(ABC):
6+
def __init__(
7+
self,
8+
payload_identifier: str,
9+
):
10+
self.payload_identifier = payload_identifier
11+
self.data = []
12+
13+
def insert(self, data: Any):
14+
self.data.append(data)
15+
16+
def find(self, identifier: str) -> Any:
17+
for entry in self.data:
18+
if getattr(entry, self.payload_identifier) == identifier:
19+
return entry
20+
return None
21+
22+
def find_all(self, identifier: List[str]) -> List[Any]:
23+
return [entry for entry in self.data if getattr(entry, self.payload_identifier) in identifier]
24+
25+
def get_all(self) -> List[Any]:
26+
return self.data if self.data else []

0 commit comments

Comments
 (0)