Initial commit for resumeformatter project
This commit is contained in:
3
backend/app/db/base.py
Normal file
3
backend/app/db/base.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# Import all the models, so that Base has them before being imported by Alembic
|
||||
from app.db.base_class import Base # noqa
|
||||
from app.models.person import Person # noqa
|
||||
13
backend/app/db/base_class.py
Normal file
13
backend/app/db/base_class.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from typing import Any
|
||||
from sqlalchemy.ext.declarative import as_declarative, declared_attr
|
||||
|
||||
|
||||
@as_declarative()
|
||||
class Base:
|
||||
id: Any
|
||||
__name__: str
|
||||
|
||||
# Generate __tablename__ automatically based on class name
|
||||
@declared_attr
|
||||
def __tablename__(cls) -> str:
|
||||
return cls.__name__.lower()
|
||||
19
backend/app/db/session.py
Normal file
19
backend/app/db/session.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from app.db.base_class import Base
|
||||
|
||||
# Use a file-based SQLite database instead of in-memory
|
||||
SQLALCHEMY_DATABASE_URL = "sqlite:///./ResumeFormatter.db"
|
||||
|
||||
engine = create_engine(
|
||||
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
|
||||
)
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
# Dependency to get DB session
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
Reference in New Issue
Block a user