MCPcopy
hub / github.com/tortoise/tortoise-orm / get_or_none

Method get_or_none

tortoise/models.py:1608–1622  ·  view source on GitHub ↗

Fetches a single record for a Model type using the provided filter parameters or None. .. code-block:: python3 user = await User.get_or_none(username="foo") :param using_db: The specific DB connection to use. :param args: Q functions containing constra

(
        cls, *args: Q, using_db: BaseDBAsyncClient | None = None, **kwargs: Any
    )

Source from the content-addressed store, hash-verified

1606
1607 @classmethod
1608 def get_or_none(
1609 cls, *args: Q, using_db: BaseDBAsyncClient | None = None, **kwargs: Any
1610 ) -> QuerySetSingle[Self | None]:
1611 """
1612 Fetches a single record for a Model type using the provided filter parameters or None.
1613
1614 .. code-block:: python3
1615
1616 user = await User.get_or_none(username="foo")
1617
1618 :param using_db: The specific DB connection to use.
1619 :param args: Q functions containing constraints. Will be AND'ed.
1620 :param kwargs: Simple filter constraints.
1621 """
1622 return cls._db_queryset(using_db).get_or_none(*args, **kwargs)
1623
1624 @classmethod
1625 async def fetch_for_list(

Callers 5

update_or_createMethod · 0.45
test_get_or_noneFunction · 0.45
test_managerFunction · 0.45
test_get_or_noneFunction · 0.45
test_noid_get_or_noneFunction · 0.45

Calls 1

_db_querysetMethod · 0.80

Tested by 4

test_get_or_noneFunction · 0.36
test_managerFunction · 0.36
test_get_or_noneFunction · 0.36
test_noid_get_or_noneFunction · 0.36