Source code for chaise.structs

 1"""
 2Various data structures used by chaise.
 3"""
 4
 5import dataclasses
 6
 7import chaise  # Be careful using this, for circular import reasons
 8
 9
[docs] 10@dataclasses.dataclass 11class AllDocs_DocRef: 12 """ 13 A document reference returned by :meth:`~chaise.Database.iter_all_docs` 14 """ 15 16 #: The document ID 17 docid: str 18 19 #: The revision of the document 20 rev: str 21 22 _db: "chaise.Database" 23 _doc: object | None 24
[docs] 25 async def doc(self): 26 """ 27 Actually get the document. Since docid+rev is roughly immutable, caches 28 it. 29 30 (Might be pre-loaded by the producing function.) 31 """ 32 if self._doc is None: 33 # docid + revision is immutable(ish), so it's safe to cache 34 # (It can still be deleted/vacuumed, but that's fine. probably.) 35 self._doc = await self._db.get(self.docid, rev=self.rev) 36 return self._doc