Gregniuki commited on
Commit
efd9b84
1 Parent(s): 50160e7

Create database.py

Browse files
Files changed (1) hide show
  1. database.py +21 -0
database.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sqlalchemy import create_engine
2
+ from sqlalchemy.orm import sessionmaker
3
+
4
+ from .models import Base
5
+
6
+ DATABASE_URL = "sqlite:///./test.db" # Update this with your database URL
7
+
8
+ engine = create_engine(DATABASE_URL)
9
+
10
+ SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
11
+
12
+ def get_db():
13
+ db = SessionLocal()
14
+ try:
15
+ yield db
16
+ finally:
17
+ db.close()
18
+
19
+ # Function to get a user by email
20
+ def get_user_by_email(db, email):
21
+ return db.query(models.User).filter(models.User.email == email).first()