forked from typeddjango/django-stubs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
django-stubs-ext: Add TypedDatabaseRouter as database router base cla…
…ss (typeddjango#1522) Base class for Django database routers. Django documentation: https://docs.djangoproject.com/en/stable/topics/db/multi-db/#automatic-database-routing Modeled after the TypedModelMeta feature Co-authored-by: Adam Johnson <[email protected]>
- Loading branch information
1 parent
c5a681d
commit 6f5fbef
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from typing import TYPE_CHECKING, Optional, Type | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
from django.db.models import Model | ||
|
||
class TypedDatabaseRouter: | ||
""" | ||
Typed base class for Django's DATABASE_ROUTERS setting. At runtime this is just an alias to `object`. | ||
All methods are optional. | ||
Django documentation: https://docs.djangoproject.com/en/stable/topics/db/multi-db/#automatic-database-routing | ||
""" | ||
|
||
def db_for_read(self, model: Type[Model], **hints: Any) -> Optional[str]: | ||
... | ||
|
||
def db_for_write(self, model: Type[Model], **hints: Any) -> Optional[str]: | ||
... | ||
|
||
def allow_relation(self, obj1: Type[Model], obj2: Type[Model], **hints: Any) -> Optional[bool]: | ||
... | ||
|
||
def allow_migrate( | ||
self, db: str, app_label: str, model_name: Optional[str] = None, **hints: Any | ||
) -> Optional[bool]: | ||
... | ||
|
||
else: | ||
TypedDatabaseRouter = object |