forked from polka_billy/porridger
Разделил модели базы данных и модели pydantic.
This commit is contained in:
59
back/db.py
59
back/db.py
@ -18,61 +18,4 @@ engine = create_engine(
|
||||
SessionLocal = sessionmaker(bind=engine, expire_on_commit=False)
|
||||
|
||||
database = SessionLocal()
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class UserDatabase(Base):#класс пользователя
|
||||
__tablename__ = "users"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)#айди пользователя
|
||||
phone = Column(Integer, nullable=True)#номер телефона пользователя
|
||||
email = Column(String)#электронная почта пользователя
|
||||
password = Column(String) # пароль
|
||||
hashed_password = Column(String)
|
||||
name = Column(String, nullable=True)#имя пользователя
|
||||
surname = Column(String)#фамилия пользователя
|
||||
|
||||
|
||||
class Announcement(Base): #класс объявления
|
||||
__tablename__ = "announcements"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)#айди объявления
|
||||
user_id = Column(Integer)#айди создателя объявления
|
||||
name = Column(String) # название объявления
|
||||
category = Column(String)#категория продукта из объявления
|
||||
best_by = Column(Integer)#срок годности продукта из объявления
|
||||
address = Column(String)
|
||||
longtitude = Column(Integer)
|
||||
latitude = Column(Integer)
|
||||
description = Column(String)#описание продукта в объявлении
|
||||
src = Column(String, nullable=True) #изображение продукта в объявлении
|
||||
metro = Column(String)#ближайщее метро от адреса нахождения продукта
|
||||
trashId = Column(Integer, nullable=True)
|
||||
booked_by = Column(Integer)#статус бронирования (либо -1, либо айди бронирующего)
|
||||
|
||||
|
||||
class Trashbox(Base):#класс мусорных баков
|
||||
__tablename__ = "trashboxes"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)#айди
|
||||
name = Column(String, nullable=True)#имя пользователя
|
||||
address = Column(String)
|
||||
latitude = Column(Integer)
|
||||
longtitude = Column(Integer)
|
||||
category = Column(String)#категория продукта из объявления
|
||||
|
||||
|
||||
# ### Функции понадобятся, когда приложение приложение будет более развитым
|
||||
# # This function can be called during the initialization of the FastAPI app.
|
||||
# async def create_db_and_tables():
|
||||
# async with engine.begin() as conn:
|
||||
# await conn.run_sync(Base.metadata.create_all)
|
||||
|
||||
|
||||
# async def get_async_session() -> AsyncGenerator[AsyncSession, None]:
|
||||
# async with async_session_maker() as session:
|
||||
# yield session
|
||||
|
||||
|
||||
# async def get_user_db(session: AsyncSession = Depends(get_async_session)):
|
||||
# yield SQLAlchemyUserDatabase(session, User)
|
||||
Base = declarative_base()
|
Reference in New Issue
Block a user