coolest edit's

This commit is contained in:
2023-10-31 23:34:08 +07:00
parent c5f744fe46
commit aed9ef0664
12 changed files with 55 additions and 38 deletions
+1 -1
View File
@@ -2,6 +2,6 @@ from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
import config
DB_CONNECT_URL = f"postgresql+asyncpg://{config.psql_login}:{config.psql_password}@{config.psql_host}/{config.psql_database}"
DB_CONNECT_URL = f"postgresql+asyncpg://{config.DB_LOGIN}:{config.DB_PASSWORD}@{config.DB_HOST}/{config.DB_NAME}"
engine = create_async_engine(DB_CONNECT_URL)
async_session = async_sessionmaker(engine)
+1 -1
View File
@@ -11,5 +11,5 @@ class UsersTokens(Base):
id = Column("id", BigInteger, Identity(start=1, increment=1, minvalue=1, cycle=False, cache=1), nullable=False,
primary_key=True)
vkid = Column("vkid", BigInteger, nullable=False)
vkid = Column("vkid", BigInteger, nullable=False, unique=True)
token = Column("token", Text, nullable=False)
+4 -2
View File
@@ -1,3 +1,5 @@
from typing import Optional
from loguru import logger
from sqlalchemy import select
@@ -20,7 +22,7 @@ async def execute_statement(statement) -> None:
# return None
async def get_user_token(user_id: int) -> str:
async def get_user_token(user_id: int) -> Optional[db.models.UsersTokens]:
"""
Возвращает токен пользователя
:param user_id: VKID
@@ -29,7 +31,7 @@ async def get_user_token(user_id: int) -> str:
try:
async with db.config.async_session() as session:
result = await session.execute(select(db.models.UsersTokens).where(db.models.UsersTokens.vkid == user_id))
return await result.scalars().one_or_none()
return result.scalars().one_or_none()
except Exception as e:
logger.exception(e)