Files
François Voron 72aa68c462 Native model and generic ID (#971)
* Use a generic Protocol model for User instead of Pydantic

* Remove UserDB Pydantic schema

* Harmonize schema variable naming to avoid confusions

* Revamp OAuth account model management

* Revamp AccessToken DB strategy to adopt generic model approach

* Make ID a generic instead of forcing UUIDs

* Improve generic typing

* Improve Strategy typing

* Tweak base DB typing

* Don't set Pydantic schemas on FastAPIUsers class: pass it directly on router creation

* Add IntegerIdMixin and export related classes

* Start to revamp doc for V10

* Revamp OAuth documentation

* Fix code highlights

* Write the 9.x.x ➡️ 10.x.x migration doc

* Fix pyproject.toml
2022-05-05 14:51:19 +02:00

51 lines
1.6 KiB
Python

from typing import Any, Dict, Generic, Optional
from fastapi_users.models import ID, OAP, UOAP, UP
from fastapi_users.types import DependencyCallable
class BaseUserDatabase(Generic[UP, ID]):
"""Base adapter for retrieving, creating and updating users from a database."""
async def get(self, id: ID) -> Optional[UP]:
"""Get a single user by id."""
raise NotImplementedError()
async def get_by_email(self, email: str) -> Optional[UP]:
"""Get a single user by email."""
raise NotImplementedError()
async def get_by_oauth_account(self, oauth: str, account_id: str) -> Optional[UP]:
"""Get a single user by OAuth account id."""
raise NotImplementedError()
async def create(self, create_dict: Dict[str, Any]) -> UP:
"""Create a user."""
raise NotImplementedError()
async def update(self, user: UP, update_dict: Dict[str, Any]) -> UP:
"""Update a user."""
raise NotImplementedError()
async def delete(self, user: UP) -> None:
"""Delete a user."""
raise NotImplementedError()
async def add_oauth_account(
self: "BaseUserDatabase[UOAP, ID]", user: UOAP, create_dict: Dict[str, Any]
) -> UOAP:
"""Create an OAuth account and add it to the user."""
raise NotImplementedError()
async def update_oauth_account(
self: "BaseUserDatabase[UOAP, ID]",
user: UOAP,
oauth_account: OAP,
update_dict: Dict[str, Any],
) -> UOAP:
"""Update an OAuth account on a user."""
raise NotImplementedError()
UserDatabaseDependency = DependencyCallable[BaseUserDatabase[UP, ID]]