-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase-schema.py
32 lines (25 loc) · 1018 Bytes
/
database-schema.py
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
30
31
32
from sqlalchemy import Column, Integer, String, ARRAY, DateTime
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime
Base = declarative_base()
class ResearchResult(Base):
__tablename__ = "research_results"
id = Column(Integer, primary_key=True, index=True)
topic = Column(String, index=True)
findings = Column(ARRAY(String))
sources = Column(ARRAY(String))
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
# Add this to your main.py or a separate database.py file
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
SQLALCHEMY_DATABASE_URL = "postgresql://user:password@postgres/dbname"
engine = create_engine(SQLALCHEMY_DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Dependency to get DB session
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()