File size: 778 Bytes
5134246
efd9b84
5134246
 
 
 
efd9b84
5134246
efd9b84
 
 
 
 
8ad755e
40adb37
8ad755e
 
 
efd9b84
 
 
 
 
 
 
 
 
eedb411
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# database.py

from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
from base import Base
from models import User

# Your database-related code here
DATABASE_URL = "sqlite:///./test.db"  # Update this with your database URL

engine = create_engine(DATABASE_URL)


# Create the tables defined in your models.
Base.metadata.create_all(bind=engine, checkfirst=True)

# You can remove the 'SessionLocal' setup if you're using FastAPI's Dependency system.
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()

# Function to get a user by email
def get_user_by_email(db, email):
    return db.query(User).filter(User.email == email).first()