Improve database backend types (#1132)

* Improve database backend types

* fixes
This commit is contained in:
Adam Johnson
2022-08-28 09:15:22 +01:00
committed by GitHub
parent 11c587867d
commit bfad3b05c1
4 changed files with 25 additions and 16 deletions

View File

@@ -12,6 +12,7 @@ from django.db.backends.base.validation import BaseDatabaseValidation
from django.db.backends.utils import CursorDebugWrapper, CursorWrapper from django.db.backends.utils import CursorDebugWrapper, CursorWrapper
NO_DB_ALIAS: str NO_DB_ALIAS: str
RAN_DB_VERSION_CHECK: Set[str]
_T = TypeVar("_T", bound="BaseDatabaseWrapper") _T = TypeVar("_T", bound="BaseDatabaseWrapper")
_ExecuteWrapper = Callable[[Callable[[str, Any, bool, Dict[str, Any]], Any], str, Any, bool, Dict[str, Any]], Any] _ExecuteWrapper = Callable[[Callable[[str, Any, bool, Dict[str, Any]], Any], str, Any, bool, Dict[str, Any]], Any]
@@ -64,6 +65,8 @@ class BaseDatabaseWrapper:
def queries_logged(self) -> bool: ... def queries_logged(self) -> bool: ...
@property @property
def queries(self) -> List[Dict[str, str]]: ... def queries(self) -> List[Dict[str, str]]: ...
def get_database_version(self) -> Tuple[int, ...]: ...
def check_database_version_supported(self) -> None: ...
def get_connection_params(self) -> Dict[str, Any]: ... def get_connection_params(self) -> Dict[str, Any]: ...
def get_new_connection(self, conn_params: Any) -> Any: ... def get_new_connection(self, conn_params: Any) -> Any: ...
def init_connection_state(self) -> None: ... def init_connection_state(self) -> None: ...
@@ -105,6 +108,8 @@ class BaseDatabaseWrapper:
def make_cursor(self, cursor: CursorWrapper) -> CursorWrapper: ... def make_cursor(self, cursor: CursorWrapper) -> CursorWrapper: ...
@contextmanager @contextmanager
def temporary_connection(self) -> Generator[CursorWrapper, None, None]: ... def temporary_connection(self) -> Generator[CursorWrapper, None, None]: ...
@contextmanager
def _nodb_cursor(self) -> Generator[CursorWrapper, None, None]: ...
def schema_editor(self, *args: Any, **kwargs: Any) -> BaseDatabaseSchemaEditor: ... def schema_editor(self, *args: Any, **kwargs: Any) -> BaseDatabaseSchemaEditor: ...
def on_commit(self, func: Callable[[], None]) -> None: ... def on_commit(self, func: Callable[[], None]) -> None: ...
def run_and_clear_commit_hooks(self) -> None: ... def run_and_clear_commit_hooks(self) -> None: ...

View File

@@ -1,14 +1,16 @@
from typing import Any, Dict, Optional, Set, Type from typing import Any, Dict, Optional, Sequence, Set, Tuple, Type
from django.db.backends.base.base import BaseDatabaseWrapper from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models.base import Model from django.db.models.base import Model
from django.db.utils import DatabaseError
class BaseDatabaseFeatures: class BaseDatabaseFeatures:
minimum_database_version: Optional[Tuple[int, ...]]
gis_enabled: bool gis_enabled: bool
allows_group_by_lob: bool allows_group_by_lob: bool
allows_group_by_pk: bool allows_group_by_pk: bool
allows_group_by_selected_pks: bool allows_group_by_selected_pks: bool
empty_fetchmany_value: Any empty_fetchmany_value: Sequence[Any]
update_can_self_select: bool update_can_self_select: bool
interprets_empty_strings_as_nulls: bool interprets_empty_strings_as_nulls: bool
supports_nullable_unique_constraints: bool supports_nullable_unique_constraints: bool
@@ -45,15 +47,14 @@ class BaseDatabaseFeatures:
nulls_order_largest: bool nulls_order_largest: bool
supports_order_by_nulls_modifier: bool supports_order_by_nulls_modifier: bool
order_by_nulls_first: bool order_by_nulls_first: bool
max_query_params: Any max_query_params: Optional[int]
allows_auto_pk_0: bool allows_auto_pk_0: bool
can_defer_constraint_checks: bool can_defer_constraint_checks: bool
supports_mixed_date_datetime_comparisons: bool
supports_tablespaces: bool supports_tablespaces: bool
supports_sequence_reset: bool supports_sequence_reset: bool
can_introspect_default: bool can_introspect_default: bool
can_introspect_foreign_keys: bool can_introspect_foreign_keys: bool
introspected_field_types: Any introspected_field_types: Dict[str, str]
supports_index_column_ordering: bool supports_index_column_ordering: bool
can_introspect_materialized_views: bool can_introspect_materialized_views: bool
can_distinct_on_fields: bool can_distinct_on_fields: bool
@@ -63,6 +64,7 @@ class BaseDatabaseFeatures:
supports_combined_alters: bool supports_combined_alters: bool
supports_foreign_keys: bool supports_foreign_keys: bool
can_create_inline_fk: bool can_create_inline_fk: bool
can_rename_index: bool
indexes_foreign_keys: bool indexes_foreign_keys: bool
supports_column_check_constraints: bool supports_column_check_constraints: bool
supports_table_check_constraints: bool supports_table_check_constraints: bool
@@ -70,7 +72,7 @@ class BaseDatabaseFeatures:
supports_paramstyle_pyformat: bool supports_paramstyle_pyformat: bool
requires_literal_defaults: bool requires_literal_defaults: bool
connection_persists_old_columns: bool connection_persists_old_columns: bool
closed_cursor_error_class: Any closed_cursor_error_class: Type[DatabaseError]
has_case_insensitive_like: bool has_case_insensitive_like: bool
bare_select_suffix: str bare_select_suffix: str
implied_column_null: bool implied_column_null: bool
@@ -94,10 +96,11 @@ class BaseDatabaseFeatures:
create_test_procedure_without_params_sql: Optional[str] create_test_procedure_without_params_sql: Optional[str]
create_test_procedure_with_int_param_sql: Optional[str] create_test_procedure_with_int_param_sql: Optional[str]
supports_callproc_kwargs: bool supports_callproc_kwargs: bool
supported_explain_formats: Set[Any] supported_explain_formats: Set[str]
validates_explain_options: bool
supports_default_in_lead_lag: bool supports_default_in_lead_lag: bool
supports_ignore_conflicts: bool supports_ignore_conflicts: bool
supports_update_conflicts: bool
supports_update_conflicts_with_target: bool
requires_casted_case_in_updates: bool requires_casted_case_in_updates: bool
supports_partial_indexes: bool supports_partial_indexes: bool
supports_functions_in_partial_indexes: bool supports_functions_in_partial_indexes: bool
@@ -118,6 +121,7 @@ class BaseDatabaseFeatures:
supports_collation_on_textfield: bool supports_collation_on_textfield: bool
supports_non_deterministic_collations: bool supports_non_deterministic_collations: bool
test_collations: Dict[str, Optional[str]] test_collations: Dict[str, Optional[str]]
test_now_utc_template: Optional[str]
django_test_expected_failures: Set[str] django_test_expected_failures: Set[str]
django_test_skips: Dict[str, Set[str]] django_test_skips: Dict[str, Set[str]]
connection: BaseDatabaseWrapper connection: BaseDatabaseWrapper

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional, Type from typing import Any, Container, Dict, Optional, Tuple, Type
from django.db.backends.base.base import BaseDatabaseWrapper as BaseDatabaseWrapper from django.db.backends.base.base import BaseDatabaseWrapper as BaseDatabaseWrapper
from typing_extensions import Literal from typing_extensions import Literal
@@ -57,16 +57,16 @@ class DatabaseWrapper(BaseDatabaseWrapper):
def check_constraints(self, table_names: Optional[Any] = ...) -> None: ... def check_constraints(self, table_names: Optional[Any] = ...) -> None: ...
def is_usable(self) -> bool: ... def is_usable(self) -> bool: ...
@property @property
def display_name(self) -> str: ... # type: ignore def display_name(self) -> str: ... # type: ignore [override]
@property @property
def data_type_check_constraints(self): ... def data_type_check_constraints(self) -> Dict[str, str]: ... # type: ignore [override]
@property @property
def mysql_server_data(self) -> Dict[str, Any]: ... def mysql_server_data(self) -> Dict[str, Any]: ...
@property @property
def mysql_server_info(self): ... def mysql_server_info(self) -> str: ...
@property @property
def mysql_version(self): ... def mysql_version(self) -> Tuple[int, ...]: ...
@property @property
def mysql_is_mariadb(self): ... def mysql_is_mariadb(self) -> bool: ...
@property @property
def sql_mode(self): ... def sql_mode(self) -> Container[str]: ...

View File

@@ -48,7 +48,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
@property @property
def can_introspect_foreign_keys(self) -> bool: ... # type: ignore def can_introspect_foreign_keys(self) -> bool: ... # type: ignore
@property @property
def introspected_field_types(self) -> Dict[str, str]: ... def introspected_field_types(self) -> Dict[str, str]: ... # type: ignore [override]
@property @property
def can_return_columns_from_insert(self) -> bool: ... # type: ignore def can_return_columns_from_insert(self) -> bool: ... # type: ignore
@property @property