Runs a ``LIMIT 1`` select with the given ``order_bys``, merges results, runs any configured prefetch, and enforces the single-row contract (raises ``NoMatch`` / ``MultipleMatches``). Shared implementation backing :meth:`first` and :meth:`last`. :param order_
(self, order_bys: list["OrderAction"])
| 1023 | return prefix + list(user_orders) |
| 1024 | |
| 1025 | async def _fetch_single(self, order_bys: list["OrderAction"]) -> "T": |
| 1026 | """ |
| 1027 | Runs a ``LIMIT 1`` select with the given ``order_bys``, merges results, |
| 1028 | runs any configured prefetch, and enforces the single-row contract |
| 1029 | (raises ``NoMatch`` / ``MultipleMatches``). Shared implementation |
| 1030 | backing :meth:`first` and :meth:`last`. |
| 1031 | |
| 1032 | :param order_bys: fully-resolved order list to apply to the query |
| 1033 | :type order_bys: list[OrderAction] |
| 1034 | :return: the single fetched model |
| 1035 | :rtype: Model |
| 1036 | """ |
| 1037 | expr = self.build_select_expression(limit=1, order_bys=order_bys) |
| 1038 | async with self.model_config.database.get_query_executor() as executor: |
| 1039 | rows = await executor.fetch_all(expr) |
| 1040 | processed_rows = await self._process_query_result_rows(rows) |
| 1041 | if self._prefetch_related and processed_rows: |
| 1042 | processed_rows = await self._prefetch_related_models(processed_rows, rows) |
| 1043 | self.check_single_result_rows_count(processed_rows) |
| 1044 | return processed_rows[0] # type: ignore |
| 1045 | |
| 1046 | async def first(self, *args: Any, **kwargs: Any) -> "T": |
| 1047 | """ |
no test coverage detected