1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
from collections.abc import Iterable
from typing import Any
from django.db.models.query import QuerySet
def is_query_set(value: Any) -> bool:
"""Gets whether the specified value is a :see:QuerySet."""
return isinstance(value, QuerySet) # type: ignore[misc]
def is_sql(value: Any) -> bool:
"""Gets whether the specified value could be a raw SQL query."""
return isinstance(value, str)
def is_sql_with_params(value: Any) -> bool:
"""Gets whether the specified value is a tuple of a SQL query (as a string)
and a tuple of bind parameters."""
return (
isinstance(value, tuple)
and len(value) == 2
and is_sql(value[0])
and isinstance(value[1], Iterable)
and not isinstance(value[1], (str, bytes, bytearray))
)
|