forked from CausalInferenceLab/Lang2SQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathin_memory.py
More file actions
23 lines (15 loc) · 720 Bytes
/
Copy pathin_memory.py
File metadata and controls
23 lines (15 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""InMemoryStore — the V1 Store axis (★②).
Facts live in a process-local dict keyed by owner. No persistence: a restart
forgets everything. v1.5 swaps this for a SQLite-backed store implementing the
same :class:`StorePort`, with zero changes elsewhere.
"""
from __future__ import annotations
from ...core.ports.memory import Fact, StorePort
class InMemoryStore:
"""``StorePort`` over a ``dict[owner, list[Fact]]``."""
def __init__(self) -> None:
self._facts: dict[str, list[Fact]] = {}
async def add(self, fact: Fact) -> None:
self._facts.setdefault(fact.owner, []).append(fact)
async def all(self, owner: str) -> list[Fact]:
return list(self._facts.get(owner, ()))