async def last(self, field="id"): expr = self.build_select_expression() key = getattr(self.table.c, field) expr = expr.order_by(key.desc()) row = await self.database.fetch_one(expr) if not row: raise NoMatch() return self.model_cls.from_row(row, select_related=self._select_related)
async def get(self, **kwargs): if kwargs: return await self.filter(**kwargs).get() expr = self.build_select_expression().limit(2) rows = await self.database.fetch_all(expr) if not rows: raise NoMatch() if len(rows) > 1: raise MultipleMatches() return self.model_cls(dict(rows[0]))