class documentation

Represent a database connection.

Method __init__ Undocumented
Method __repr__ Undocumented
Method check_constraints Backends can override this method if they can apply constraint checking (e.g. via "SET CONSTRAINTS ALL IMMEDIATE"). Should raise an IntegrityError if any invalid foreign key references are encountered.
Method check_database_version_supported Raise an error if the database version isn't supported by this version of Django.
Method check_settings Undocumented
Method chunked_cursor Return a cursor that tries to avoid caching in the database (if supported by the database), otherwise return a regular cursor.
Method clean_savepoints Reset the counter used to generate unique savepoint ids in this thread.
Method close Close the connection to the database.
Method close_if_health_check_failed Close existing connection if it fails a health check.
Method close_if_unusable_or_obsolete Close the current connection if unrecoverable errors have occurred or if it outlived its maximum age.
Method commit Commit a transaction and reset the dirty flag.
Method connect Connect to the database. Assume that the connection is closed.
Method constraint_checks_disabled Disable foreign key constraint checking.
Method copy Return a copy of this connection.
Method create_cursor Create a cursor. Assume that a connection is established.
Method cursor Create a cursor, opening a connection if necessary.
Method dec_thread_sharing Undocumented
Method disable_constraint_checking Backends can implement as needed to temporarily disable foreign key constraint checking. Should return True if the constraints were disabled and will need to be reenabled.
Method enable_constraint_checking Backends can implement as needed to re-enable foreign key constraint checking.
Method ensure_connection Guarantee that a connection to the database is established.
Method ensure_timezone Ensure the connection's timezone is set to `self.timezone_name` and return whether it changed or not.
Method execute_wrapper Return a context manager under which the wrapper is applied to suitable database query executions.
Method get_autocommit Get the autocommit state.
Method get_connection_params Return a dict of parameters suitable for get_new_connection.
Method get_database_version Return a tuple of the database's version.
Method get_new_connection Open a connection to the database.
Method get_rollback Get the "needs rollback" flag -- for *advanced use* only.
Method inc_thread_sharing Undocumented
Method init_connection_state Initialize the database connection settings.
Method is_usable Test if the database connection is usable.
Method make_cursor Create a cursor without debug logging.
Method make_debug_cursor Create a cursor that logs all queries in self.queries_log.
Method on_commit Undocumented
Method prepare_database Hook to do any database check or preparation, generally called before migrating a project or an app.
Method rollback Roll back a transaction and reset the dirty flag.
Method run_and_clear_commit_hooks Undocumented
Method savepoint Create a savepoint inside the current transaction. Return an identifier for the savepoint that will be used for the subsequent rollback or commit. Do nothing if savepoints are not supported.
Method savepoint_commit Release a savepoint. Do nothing if savepoints are not supported.
Method savepoint_rollback Roll back to a savepoint. Do nothing if savepoints are not supported.
Method schema_editor Return a new instance of this backend's SchemaEditor.
Method set_autocommit Enable or disable autocommit.
Method set_rollback Set or unset the "needs rollback" flag -- for *advanced use* only.
Method temporary_connection Context manager that ensures that a connection is established, and if it opened one, closes it to avoid leaving a dangling connection. This is useful for operations outside of the request-response cycle.
Method validate_no_atomic_block Raise an error if an atomic block is active.
Method validate_no_broken_transaction Undocumented
Method validate_thread_sharing Validate that the connection isn't accessed by another thread than the one which originally created it, unless the connection was explicitly authorized to be shared between threads (via the `inc_thread_sharing()` method)...
Class Variable client_class Undocumented
Class Variable creation_class Undocumented
Class Variable data_type_check_constraints Undocumented
Class Variable data_types Undocumented
Class Variable data_types_suffix Undocumented
Class Variable display_name Undocumented
Class Variable features_class Undocumented
Class Variable introspection_class Undocumented
Class Variable ops_class Undocumented
Class Variable queries_limit Undocumented
Class Variable SchemaEditorClass Undocumented
Class Variable vendor Undocumented
Instance Variable alias Undocumented
Instance Variable atomic_blocks Undocumented
Instance Variable autocommit Undocumented
Instance Variable client Undocumented
Instance Variable close_at Undocumented
Instance Variable closed_in_transaction Undocumented
Instance Variable commit_on_exit Undocumented
Instance Variable connection Undocumented
Instance Variable creation Undocumented
Instance Variable errors_occurred Undocumented
Instance Variable execute_wrappers Undocumented
Instance Variable features Undocumented
Instance Variable force_debug_cursor Undocumented
Instance Variable health_check_done Undocumented
Instance Variable health_check_enabled Undocumented
Instance Variable in_atomic_block Undocumented
Instance Variable introspection Undocumented
Instance Variable needs_rollback Undocumented
Instance Variable ops Undocumented
Instance Variable queries_log Undocumented
Instance Variable run_commit_hooks_on_set_autocommit_on Undocumented
Instance Variable run_on_commit Undocumented
Instance Variable savepoint_ids Undocumented
Instance Variable savepoint_state Undocumented
Instance Variable settings_dict Undocumented
Instance Variable validation Undocumented
Property allow_thread_sharing Undocumented
Property queries Undocumented
Property queries_logged Undocumented
Property timezone Return a tzinfo of the database connection time zone.
Property timezone_name Name of the time zone of the database connection.
Property wrap_database_errors Context manager and decorator that re-throws backend-specific database exceptions using Django's common wrappers.
Method _close Undocumented
Method _commit Undocumented
Method _cursor Undocumented
Method _nodb_cursor Return a cursor from an alternative connection to be used when there is no need to access the main database, specifically for test db creation/deletion. This also prevents the production database from being exposed to potential child threads while (or after) the test database is destroyed...
Method _prepare_cursor Validate the connection is usable and perform database cursor wrapping.
Method _rollback Undocumented
Method _savepoint Undocumented
Method _savepoint_allowed Undocumented
Method _savepoint_commit Undocumented
Method _savepoint_rollback Undocumented
Method _set_autocommit Backend-specific implementation to enable or disable autocommit.
Instance Variable _thread_ident Undocumented
Instance Variable _thread_sharing_count Undocumented
Instance Variable _thread_sharing_lock Undocumented
def __repr__(self): (source)

Undocumented

def check_constraints(self, table_names=None): (source)

Backends can override this method if they can apply constraint checking (e.g. via "SET CONSTRAINTS ALL IMMEDIATE"). Should raise an IntegrityError if any invalid foreign key references are encountered.

def check_database_version_supported(self): (source)

Raise an error if the database version isn't supported by this version of Django.

def check_settings(self): (source)

Undocumented

def chunked_cursor(self): (source)

Return a cursor that tries to avoid caching in the database (if supported by the database), otherwise return a regular cursor.

@async_unsafe
def clean_savepoints(self): (source)

Reset the counter used to generate unique savepoint ids in this thread.

@async_unsafe
def close(self): (source)

Close the connection to the database.

def close_if_health_check_failed(self): (source)

Close existing connection if it fails a health check.

def close_if_unusable_or_obsolete(self): (source)

Close the current connection if unrecoverable errors have occurred or if it outlived its maximum age.

@async_unsafe
def commit(self): (source)

Commit a transaction and reset the dirty flag.

@async_unsafe
def connect(self): (source)

Connect to the database. Assume that the connection is closed.

@contextmanager
def constraint_checks_disabled(self): (source)

Disable foreign key constraint checking.

def copy(self, alias=None): (source)

Return a copy of this connection. For tests that require two connections to the same database.

@async_unsafe
def cursor(self): (source)

Create a cursor, opening a connection if necessary.

def dec_thread_sharing(self): (source)

Undocumented

def disable_constraint_checking(self): (source)

Backends can implement as needed to temporarily disable foreign key constraint checking. Should return True if the constraints were disabled and will need to be reenabled.

def enable_constraint_checking(self): (source)

Backends can implement as needed to re-enable foreign key constraint checking.

@async_unsafe
def ensure_connection(self): (source)

Guarantee that a connection to the database is established.

def ensure_timezone(self): (source)

Ensure the connection's timezone is set to `self.timezone_name` and return whether it changed or not.

@contextmanager
def execute_wrapper(self, wrapper): (source)

Return a context manager under which the wrapper is applied to suitable database query executions.

def get_autocommit(self): (source)

Get the autocommit state.

def get_rollback(self): (source)

Get the "needs rollback" flag -- for *advanced use* only.

def inc_thread_sharing(self): (source)

Undocumented

def is_usable(self): (source)

Test if the database connection is usable. This method may assume that self.connection is not None. Actual implementations should take care not to raise exceptions as that may prevent Django from recycling unusable connections.

def make_cursor(self, cursor): (source)

Create a cursor without debug logging.

def make_debug_cursor(self, cursor): (source)

Create a cursor that logs all queries in self.queries_log.

def on_commit(self, func): (source)

Undocumented

def prepare_database(self): (source)

Hook to do any database check or preparation, generally called before migrating a project or an app.

@async_unsafe
def rollback(self): (source)

Roll back a transaction and reset the dirty flag.

def run_and_clear_commit_hooks(self): (source)

Undocumented

@async_unsafe
def savepoint(self): (source)

Create a savepoint inside the current transaction. Return an identifier for the savepoint that will be used for the subsequent rollback or commit. Do nothing if savepoints are not supported.

@async_unsafe
def savepoint_commit(self, sid): (source)

Release a savepoint. Do nothing if savepoints are not supported.

@async_unsafe
def savepoint_rollback(self, sid): (source)

Roll back to a savepoint. Do nothing if savepoints are not supported.

def schema_editor(self, *args, **kwargs): (source)

Return a new instance of this backend's SchemaEditor.

def set_autocommit(self, autocommit, force_begin_transaction_with_broken_autocommit=False): (source)

Enable or disable autocommit. The usual way to start a transaction is to turn autocommit off. SQLite does not properly start a transaction when disabling autocommit. To avoid this buggy behavior and to actually enter a new transaction, an explicit BEGIN is required. Using force_begin_transaction_with_broken_autocommit=True will issue an explicit BEGIN with SQLite. This option will be ignored for other backends.

def set_rollback(self, rollback): (source)

Set or unset the "needs rollback" flag -- for *advanced use* only.

@contextmanager
def temporary_connection(self): (source)

Context manager that ensures that a connection is established, and if it opened one, closes it to avoid leaving a dangling connection. This is useful for operations outside of the request-response cycle. Provide a cursor: with self.temporary_connection() as cursor: ...

def validate_no_atomic_block(self): (source)

Raise an error if an atomic block is active.

def validate_no_broken_transaction(self): (source)

Undocumented

def validate_thread_sharing(self): (source)

Validate that the connection isn't accessed by another thread than the one which originally created it, unless the connection was explicitly authorized to be shared between threads (via the `inc_thread_sharing()` method). Raise an exception if the validation fails.

client_class = (source)

Undocumented

creation_class = (source)

Undocumented

features_class = (source)

Undocumented

introspection_class = (source)

Undocumented

ops_class = (source)

Undocumented

queries_limit: int = (source)

Undocumented

SchemaEditorClass = (source)

Undocumented

Undocumented

atomic_blocks: list = (source)

Undocumented

autocommit = (source)

Undocumented

Undocumented

close_at = (source)

Undocumented

closed_in_transaction: bool = (source)

Undocumented

commit_on_exit: bool = (source)

Undocumented

connection = (source)

Undocumented

creation = (source)

Undocumented

errors_occurred: bool = (source)

Undocumented

execute_wrappers: list = (source)

Undocumented

force_debug_cursor: bool = (source)

Undocumented

health_check_done: bool = (source)

Undocumented

health_check_enabled = (source)

Undocumented

in_atomic_block: bool = (source)

Undocumented

needs_rollback = (source)
queries_log = (source)

Undocumented

run_commit_hooks_on_set_autocommit_on: bool = (source)

Undocumented

run_on_commit: list = (source)

Undocumented

savepoint_ids: list = (source)

Undocumented

savepoint_state: int = (source)

Undocumented

settings_dict = (source)

Undocumented

validation = (source)

Undocumented

@property
allow_thread_sharing = (source)

Undocumented

Undocumented

@property
queries_logged = (source)

Undocumented

Return a tzinfo of the database connection time zone. This is only used when time zone support is enabled. When a datetime is read from the database, it is always returned in this time zone. When the database backend supports time zones, it doesn't matter which time zone Django uses, as long as aware datetimes are used everywhere. Other users connecting to the database can choose their own time zone. When the database backend doesn't support time zones, the time zone Django uses may be constrained by the requirements of other users of the database.

Name of the time zone of the database connection.

@cached_property
wrap_database_errors = (source)

Context manager and decorator that re-throws backend-specific database exceptions using Django's common wrappers.

def _close(self): (source)

Undocumented

def _commit(self): (source)
def _cursor(self, name=None): (source)

Undocumented

@contextmanager
def _nodb_cursor(self): (source)

Return a cursor from an alternative connection to be used when there is no need to access the main database, specifically for test db creation/deletion. This also prevents the production database from being exposed to potential child threads while (or after) the test database is destroyed. Refs #10868, #17786, #16969.

def _prepare_cursor(self, cursor): (source)

Validate the connection is usable and perform database cursor wrapping.

def _rollback(self): (source)
def _savepoint(self, sid): (source)

Undocumented

def _savepoint_allowed(self): (source)
def _savepoint_commit(self, sid): (source)
def _savepoint_rollback(self, sid): (source)

Undocumented

_thread_ident = (source)

Undocumented

_thread_sharing_count: int = (source)

Undocumented

_thread_sharing_lock = (source)

Undocumented