Beispiel #1
0
    def update(self, collection: str, item: Item) -> None:
        if not self.exists(collection, item):
            raise ItemNotFoundError(f"Item ( {item.id} ) not found.")

        path = self._get_item_path(collection, item)
        with path.open("w") as f:
            json.dump(item.to_dict(), f)
Beispiel #2
0
    def upsert(self, collection: str, item: Item) -> None:
        self._create_collection(collection)

        path = self._get_item_path(collection, item)

        with path.open("w") as f:
            json.dump(item.to_dict(), f)

        logger.debug("save file: %s", str(path))
Beispiel #3
0
    def insert(self, collection: str, item: Item) -> None:
        self._create_collection(collection)

        path = self._get_item_path(collection, item)

        if path.exists():
            raise ItemDuplicationError(f"Item id {item.id} already exists.")

        with path.open("w") as f:
            json.dump(item.to_dict(), f)

        logger.debug("save file: %s", str(path))