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

Method first

ormar/queryset/queryset.py:1046–1065  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 15

first_or_noneMethod · 0.95
test_filter_enumFunction · 0.45
test_uuid_columnFunction · 0.45
test_model_firstFunction · 0.45
test_get_and_firstFunction · 0.45
test_queryset_methodsFunction · 0.45
test_selecting_relatedFunction · 0.45
test_selecting_relatedFunction · 0.45
test_selecting_relatedFunction · 0.45

Calls 3

filterMethod · 0.95
_fetch_singleMethod · 0.95
_single_row_order_bysMethod · 0.95

Tested by 12

test_filter_enumFunction · 0.36
test_uuid_columnFunction · 0.36
test_model_firstFunction · 0.36
test_get_and_firstFunction · 0.36
test_queryset_methodsFunction · 0.36
test_selecting_relatedFunction · 0.36
test_selecting_relatedFunction · 0.36
test_selecting_relatedFunction · 0.36
firstFunction · 0.36