start-pack
This commit is contained in:
commit
3e1fa59b3d
5723 changed files with 757971 additions and 0 deletions
63
myenv/lib/python3.12/site-packages/django/db/__init__.py
Normal file
63
myenv/lib/python3.12/site-packages/django/db/__init__.py
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
from django.core import signals
|
||||
from django.db.utils import (
|
||||
DEFAULT_DB_ALIAS,
|
||||
DJANGO_VERSION_PICKLE_KEY,
|
||||
ConnectionHandler,
|
||||
ConnectionRouter,
|
||||
DatabaseError,
|
||||
DataError,
|
||||
Error,
|
||||
IntegrityError,
|
||||
InterfaceError,
|
||||
InternalError,
|
||||
NotSupportedError,
|
||||
OperationalError,
|
||||
ProgrammingError,
|
||||
)
|
||||
from django.utils.connection import ConnectionProxy
|
||||
|
||||
__all__ = [
|
||||
"close_old_connections",
|
||||
"connection",
|
||||
"connections",
|
||||
"reset_queries",
|
||||
"router",
|
||||
"DatabaseError",
|
||||
"IntegrityError",
|
||||
"InternalError",
|
||||
"ProgrammingError",
|
||||
"DataError",
|
||||
"NotSupportedError",
|
||||
"Error",
|
||||
"InterfaceError",
|
||||
"OperationalError",
|
||||
"DEFAULT_DB_ALIAS",
|
||||
"DJANGO_VERSION_PICKLE_KEY",
|
||||
]
|
||||
|
||||
connections = ConnectionHandler()
|
||||
|
||||
router = ConnectionRouter()
|
||||
|
||||
# For backwards compatibility. Prefer connections['default'] instead.
|
||||
connection = ConnectionProxy(connections, DEFAULT_DB_ALIAS)
|
||||
|
||||
|
||||
# Register an event to reset saved queries when a Django request is started.
|
||||
def reset_queries(**kwargs):
|
||||
for conn in connections.all(initialized_only=True):
|
||||
conn.queries_log.clear()
|
||||
|
||||
|
||||
signals.request_started.connect(reset_queries)
|
||||
|
||||
|
||||
# Register an event to reset transaction state and close connections past
|
||||
# their lifetime.
|
||||
def close_old_connections(**kwargs):
|
||||
for conn in connections.all(initialized_only=True):
|
||||
conn.close_if_unusable_or_obsolete()
|
||||
|
||||
|
||||
signals.request_started.connect(close_old_connections)
|
||||
signals.request_finished.connect(close_old_connections)
|
||||
Loading…
Add table
Add a link
Reference in a new issue