[docs]@dataclass(eq=True,slots=True,unsafe_hash=True,order=True,kw_only=True,frozen=True)classBotVersion(CachedModel,metaclass=SingletonCachedByKey):"""A class to represent the version of the bot in the database"""id:int
[docs]defget_cache_key(self)->str:"""Get the cache key for the bot version."""returnf"{self.id}"
[docs]@maybe_cachedasyncdeffetch_version(self)->Version:"""Fetch the version of the bot from the database"""data=(awaitBotVersionRow.select(BotVersionRow.version).where(BotVersionRow.bot==self.id).first().output(load_json=True,nested=True))returntyping.cast(Version,parse(data["version"]ifdataelseBotVersionRow.version.default))
[docs]asyncdefupdate_version(self,version:Version|str)->None:"""Update the version of the bot in the database"""awaitBotVersionRow.insert(BotVersionRow(bot=self.id,version=str(version))).on_conflict(action="DO UPDATE",target=BotVersionRow.bot,values=[BotVersionRow.version])