Пример #1
0
 async def put(self, obj: KVPair) -> Tuple[Optional[KVPair], KVPair]:
     if old_doc := (await self.collections.find_one({"key": obj.key})):
         await self.collections.replace_one({"_id": old_doc["_id"]},
                                            obj.dump())
         return KVPair.load(old_doc), obj
Пример #2
0
 async def get(self, key: str) -> KVPair:
     doc: dict = await self.collections.find_one({"key": key})
     return KVPair.load(doc) if doc else None
Пример #3
0
 async def has_field(self, field: str) -> AsyncGenerator[KVPair, None]:
     async for doc in self.collections.find({field: {"$exists": True}}):
         yield KVPair.load(doc)
Пример #4
0
 async def iter(self) -> AsyncGenerator[KVPair, None]:
     async for doc in self.collections.find():
         yield KVPair.load(doc)