mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2026-03-13 07:49:55 +08:00
Implement MongoDB database adapter (#29)
* Implement MongoDB adapter using motor * Add mongo container to build pipeline * Tidy up dependencies * Update documentation for MongoDB * Export MongoDB adapter from db package * Pass black format * Update README
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import List, cast
|
||||
from typing import List, Optional, cast
|
||||
|
||||
from databases import Database
|
||||
from sqlalchemy import Boolean, Column, String, Table
|
||||
@@ -38,11 +38,11 @@ class SQLAlchemyUserDatabase(BaseUserDatabase):
|
||||
query = self.users.select()
|
||||
return cast(List[BaseUserDB], await self.database.fetch_all(query))
|
||||
|
||||
async def get(self, id: str) -> BaseUserDB:
|
||||
async def get(self, id: str) -> Optional[BaseUserDB]:
|
||||
query = self.users.select().where(self.users.c.id == id)
|
||||
return cast(BaseUserDB, await self.database.fetch_one(query))
|
||||
|
||||
async def get_by_email(self, email: str) -> BaseUserDB:
|
||||
async def get_by_email(self, email: str) -> Optional[BaseUserDB]:
|
||||
query = self.users.select().where(self.users.c.email == email)
|
||||
return cast(BaseUserDB, await self.database.fetch_one(query))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user