Первые шаги подключения BD к API
This commit is contained in:
23
backend-app/database.py
Normal file
23
backend-app/database.py
Normal file
@ -0,0 +1,23 @@
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker, AsyncSession, create_async_engine
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
|
||||
class Model(DeclarativeBase):
|
||||
pass
|
||||
|
||||
|
||||
async_engine=create_async_engine(
|
||||
url = "mssql+aioodbc://sa:159357"\
|
||||
"@10.124.30.208:1433/test_db"\
|
||||
"?driver=ODBC+Driver+17+for+SQL+Server",
|
||||
connect_args={"check_same_thread": False}
|
||||
)
|
||||
|
||||
async_session = async_sessionmaker(
|
||||
async_engine,
|
||||
autoflush=True,
|
||||
autocommit=False,
|
||||
expire_on_commit =False
|
||||
)
|
||||
# async def get_async_session() -> AsyncSession:
|
||||
# async with async_session() as session:
|
||||
# session.
|
0
backend-app/repo/__init__.py
Normal file
0
backend-app/repo/__init__.py
Normal file
0
backend-app/repo/crud.py
Normal file
0
backend-app/repo/crud.py
Normal file
21
backend-app/repo/model.py
Normal file
21
backend-app/repo/model.py
Normal file
@ -0,0 +1,21 @@
|
||||
from database import Model
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy import String, Integer, Boolean, ForeignKey
|
||||
from typing import Optional, Sequence
|
||||
|
||||
class UserModel(Model):
|
||||
__tablename__ ="users"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
firstname: Mapped[str | None]= mapped_column(String(255), nullable=True)
|
||||
lastname: Mapped[str | None]= mapped_column(String(255), nullable=True)
|
||||
age: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
email: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
login_id: Mapped[int] = mapped_column(Integer, ForeignKey("logins.id"))
|
||||
|
||||
class LoginModel(Model):
|
||||
__tablename__ ="logins"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
login: Mapped[str]= mapped_column(String(255), nullable=False)
|
||||
password: Mapped[str]= mapped_column(String(255), nullable=False)
|
2
backend-app/repo/schema.py
Normal file
2
backend-app/repo/schema.py
Normal file
@ -0,0 +1,2 @@
|
||||
from pydantic import BaseModel
|
||||
|
Reference in New Issue
Block a user