mirror of
https://github.com/a-mayb3/Kanban_clone_backend.git
synced 2026-03-21 10:05:38 +01:00
32 lines
No EOL
802 B
Python
32 lines
No EOL
802 B
Python
|
|
import sqlalchemy
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
|
|
from pydantic import BaseModel, ConfigDict
|
|
|
|
from fastapi import Depends
|
|
from sqlalchemy.orm import Session
|
|
from typing import Annotated
|
|
|
|
URL_DATABASE = "sqlite:///./kanban_clone.db"
|
|
|
|
engine = create_engine(URL_DATABASE, echo=True)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
Base = declarative_base()
|
|
|
|
def init_db() -> None:
|
|
# Import models so they are registered with SQLAlchemy metadata
|
|
import models # noqa: F401
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
db_dependency = Annotated[Session, Depends(get_db)] |