AutoRpa/rpa_oms/app/inbound/memory_repo.py

26 lines
706 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""内存仓库。只给单测用,进程退出即丢。运行时走 Oracle。
按 oms_id 判重,已存在就 DuplicateOmsId,不覆盖。
"""
from __future__ import annotations
from .repo import DuplicateOmsId
class MemorySalesGoodsRepo:
def __init__(self):
self._rows: dict[int, dict] = {}
def insert(self, record: dict) -> None:
oms_id = record["oms_id"]
if oms_id in self._rows:
raise DuplicateOmsId(oms_id)
self._rows[oms_id] = dict(record)
def get(self, oms_id: int) -> dict | None:
row = self._rows.get(oms_id)
return dict(row) if row is not None else None
def count(self) -> int:
return len(self._rows)