MCPcopy Create free account
hub / github.com/ormar-orm/ormar / first_or_none

Method first_or_none

ormar/queryset/queryset.py:1067–1082  ·  view source on GitHub ↗

Gets the first row from the db ordered by primary key column ascending. Behaves like :meth:`first` but returns ``None`` instead of raising ``NoMatch`` when no row matches. :param kwargs: fields names and proper value types :type kwargs: Any :return:

(self, *args: Any, **kwargs: Any)

Source from the content-addressed store, hash-verified

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 """
1069 Gets the first row from the db ordered by primary key column ascending.
1070
1071 Behaves like :meth:`first` but returns ``None`` instead of raising
1072 ``NoMatch`` when no row matches.
1073
1074 :param kwargs: fields names and proper value types
1075 :type kwargs: Any
1076 :return: returned model or None
1077 :rtype: Optional[Model]
1078 """
1079 try:
1080 return await self.first(*args, **kwargs)
1081 except ormar.NoMatch:
1082 return None
1083
1084 async def last(self, *args: Any, **kwargs: Any) -> "T":
1085 """

Callers 2

test_proxy_first_or_noneFunction · 0.45
test_model_firstFunction · 0.45

Calls 1

firstMethod · 0.95

Tested by 2

test_proxy_first_or_noneFunction · 0.36
test_model_firstFunction · 0.36