basic profile
This commit is contained in:
25
packages/backend/app/database.py
Normal file
25
packages/backend/app/database.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import os
|
||||
from sqlalchemy import create_engine
|
||||
# MODIFICA: La best practice moderna è usare DeclarativeBase
|
||||
from sqlalchemy.orm import sessionmaker, DeclarativeBase
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
DATABASE_URL = os.getenv("DATABASE_URL")
|
||||
|
||||
engine = create_engine(DATABASE_URL)
|
||||
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
# Assicurati che Base sia definito così
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
# Dependency per ottenere una sessione DB per ogni richiesta
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
Reference in New Issue
Block a user