-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.py
33 lines (25 loc) · 1013 Bytes
/
database.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
33
from sqlalchemy import create_engine, Column, Integer, String, Float, DateTime
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime
from dotenv import load_dotenv
import os
import io
load_dotenv()
# Define the database connection settings
SQLALCHEMY_DATABASE_URL = os.getenv("DATABASE_URL")
# Create the database engine
engine = create_engine(SQLALCHEMY_DATABASE_URL)
# Create a SessionLocal class to handle database sessions
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Define a Base class for declarative SQLAlchemy models
Base = declarative_base()
# Define the StockData model
class StockData(Base):
__tablename__ = "stock_data"
id = Column(Integer, primary_key=True, index=True)
stock_name = Column(String)
stock_price = Column(Float)
model_accuracy = Column(Float)
prediction_date = Column(DateTime, default=datetime.today().date())
Base.metadata.create_all(bind=engine)