MCPcopy
hub / github.com/ormar-orm/ormar / _fetch_single

Method _fetch_single

ormar/queryset/queryset.py:1025–1044  ·  view source on GitHub ↗

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"])

Source from the content-addressed store, hash-verified

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 """

Callers 2

firstMethod · 0.95
lastMethod · 0.95

Calls 6

get_query_executorMethod · 0.80
fetch_allMethod · 0.80

Tested by

no test coverage detected