1
1
"""FastAPI Users database adapter for SQLAlchemy."""
2
+
2
3
import uuid
3
- from typing import TYPE_CHECKING , Any , Dict , Generic , Optional , Type
4
+ from typing import TYPE_CHECKING , Any , Generic , Optional
4
5
5
6
from fastapi_users .db .base import BaseUserDatabase
6
7
from fastapi_users .models import ID , OAP , UP
@@ -103,14 +104,14 @@ class SQLAlchemyUserDatabase(Generic[UP, ID], BaseUserDatabase[UP, ID]):
103
104
"""
104
105
105
106
session : AsyncSession
106
- user_table : Type [UP ]
107
- oauth_account_table : Optional [Type [SQLAlchemyBaseOAuthAccountTable ]]
107
+ user_table : type [UP ]
108
+ oauth_account_table : Optional [type [SQLAlchemyBaseOAuthAccountTable ]]
108
109
109
110
def __init__ (
110
111
self ,
111
112
session : AsyncSession ,
112
- user_table : Type [UP ],
113
- oauth_account_table : Optional [Type [SQLAlchemyBaseOAuthAccountTable ]] = None ,
113
+ user_table : type [UP ],
114
+ oauth_account_table : Optional [type [SQLAlchemyBaseOAuthAccountTable ]] = None ,
114
115
):
115
116
self .session = session
116
117
self .user_table = user_table
@@ -138,14 +139,14 @@ async def get_by_oauth_account(self, oauth: str, account_id: str) -> Optional[UP
138
139
)
139
140
return await self ._get_user (statement )
140
141
141
- async def create (self , create_dict : Dict [str , Any ]) -> UP :
142
+ async def create (self , create_dict : dict [str , Any ]) -> UP :
142
143
user = self .user_table (** create_dict )
143
144
self .session .add (user )
144
145
await self .session .commit ()
145
146
await self .session .refresh (user )
146
147
return user
147
148
148
- async def update (self , user : UP , update_dict : Dict [str , Any ]) -> UP :
149
+ async def update (self , user : UP , update_dict : dict [str , Any ]) -> UP :
149
150
for key , value in update_dict .items ():
150
151
setattr (user , key , value )
151
152
self .session .add (user )
@@ -157,7 +158,7 @@ async def delete(self, user: UP) -> None:
157
158
await self .session .delete (user )
158
159
await self .session .commit ()
159
160
160
- async def add_oauth_account (self , user : UP , create_dict : Dict [str , Any ]) -> UP :
161
+ async def add_oauth_account (self , user : UP , create_dict : dict [str , Any ]) -> UP :
161
162
if self .oauth_account_table is None :
162
163
raise NotImplementedError ()
163
164
@@ -172,7 +173,7 @@ async def add_oauth_account(self, user: UP, create_dict: Dict[str, Any]) -> UP:
172
173
return user
173
174
174
175
async def update_oauth_account (
175
- self , user : UP , oauth_account : OAP , update_dict : Dict [str , Any ]
176
+ self , user : UP , oauth_account : OAP , update_dict : dict [str , Any ]
176
177
) -> UP :
177
178
if self .oauth_account_table is None :
178
179
raise NotImplementedError ()
0 commit comments