Gets the first row from the db ordered by primary key column ascending. Passing args and/or kwargs is a shortcut and equals to calling ``filter(*args, **kwargs).first()``. The query is always executed with ``LIMIT 1`` so at most one row is fetched; use :met
(self, *args: Any, **kwargs: Any)
| 1044 | return processed_rows[0] # type: ignore |
| 1045 | |
| 1046 | async def first(self, *args: Any, **kwargs: Any) -> "T": |
| 1047 | """ |
| 1048 | Gets the first row from the db ordered by primary key column ascending. |
| 1049 | |
| 1050 | Passing args and/or kwargs is a shortcut and equals to calling |
| 1051 | ``filter(*args, **kwargs).first()``. |
| 1052 | |
| 1053 | The query is always executed with ``LIMIT 1`` so at most one row is |
| 1054 | fetched; use :meth:`get` if you want to assert that the criteria |
| 1055 | match exactly one row. |
| 1056 | |
| 1057 | :raises NoMatch: if no rows match the criteria |
| 1058 | :param kwargs: fields names and proper value types |
| 1059 | :type kwargs: Any |
| 1060 | :return: returned model |
| 1061 | :rtype: Model |
| 1062 | """ |
| 1063 | if kwargs or args: |
| 1064 | return await self.filter(*args, **kwargs).first() |
| 1065 | return await self._fetch_single(self._single_row_order_bys(reverse=False)) |
| 1066 | |
| 1067 | async def first_or_none(self, *args: Any, **kwargs: Any) -> Optional["T"]: |
| 1068 | """ |