-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
31 lines (25 loc) · 787 Bytes
/
Copy pathdatabase.py
File metadata and controls
31 lines (25 loc) · 787 Bytes
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
from sqlalchemy import Integer, String, Float, DateTime, create_engine, Column
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime
import os
from dotenv import load_dotenv
load_dotenv()
DB_URL = os.getenv("DATABASE_URL")
engine = create_engine(DB_URL)
Session = sessionmaker(bind=engine)
Base = declarative_base()
class Tasks(Base):
__tablename__ = "tasks"
id = Column(Integer, primary_key=True)
task = Column(String, nullable=True)
status = Column(String, nullable=True)
result = Column(String, nullable=True)
time = Column(DateTime, default=datetime.utcnow)
Base.metadata.create_all(engine)
def get_db():
db = Session()
try:
yield db
finally:
db.close()