Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change deprecated sqlmodel method #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions fastapi_users_db_sqlmodel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from fastapi_users.db.base import BaseUserDatabase
from fastapi_users.models import ID, OAP, UP
from pydantic import UUID4, EmailStr
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload
from sqlmodel import Field, Session, SQLModel, func, select
from sqlmodel.ext.asyncio.session import AsyncSession

__version__ = "0.3.0"

Expand Down Expand Up @@ -174,11 +174,11 @@ async def get_by_email(self, email: str) -> Optional[UP]:
statement = select(self.user_model).where( # type: ignore
func.lower(self.user_model.email) == func.lower(email)
)
results = await self.session.execute(statement)
results = await self.session.exec(statement)
object = results.first()
if object is None:
return None
return object[0]
return object

async def get_by_oauth_account(self, oauth: str, account_id: str) -> Optional[UP]:
"""Get a single user by OAuth account id."""
Expand All @@ -190,10 +190,10 @@ async def get_by_oauth_account(self, oauth: str, account_id: str) -> Optional[UP
.where(self.oauth_account_model.account_id == account_id)
.options(selectinload(self.oauth_account_model.user)) # type: ignore
)
results = await self.session.execute(statement)
results = await self.session.exec(statement)
oauth_account = results.first()
if oauth_account:
user = oauth_account[0].user # type: ignore
user = oauth_account.user # type: ignore
return user
return None

Expand Down
10 changes: 5 additions & 5 deletions fastapi_users_db_sqlmodel/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from fastapi_users.authentication.strategy.db import AP, AccessTokenDatabase
from pydantic import UUID4
from sqlalchemy import Column, types
from sqlalchemy.ext.asyncio import AsyncSession
from sqlmodel import Field, Session, SQLModel, select
from sqlmodel.ext.asyncio.session import AsyncSession

from fastapi_users_db_sqlmodel.generics import TIMESTAMPAware, now_utc

Expand Down Expand Up @@ -49,11 +49,11 @@ async def get_by_token(
if max_age is not None:
statement = statement.where(self.access_token_model.created_at >= max_age)

results = self.session.execute(statement)
results = self.session.exec(statement)
access_token = results.first()
if access_token is None:
return None
return access_token[0]
return access_token

async def create(self, create_dict: Dict[str, Any]) -> AP:
access_token = self.access_token_model(**create_dict)
Expand Down Expand Up @@ -96,11 +96,11 @@ async def get_by_token(
if max_age is not None:
statement = statement.where(self.access_token_model.created_at >= max_age)

results = await self.session.execute(statement)
results = await self.session.exec(statement)
access_token = results.first()
if access_token is None:
return None
return access_token[0]
return access_token

async def create(self, create_dict: Dict[str, Any]) -> AP:
access_token = self.access_token_model(**create_dict)
Expand Down
Loading