Add Task to database
This commit is contained in:
parent
e00887e973
commit
bc1bbed07f
2 changed files with 20 additions and 1 deletions
19
db/Task.py
Normal file
19
db/Task.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from db import Base
|
||||
from sqlalchemy import Column, Integer, String, BigInteger, Date
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class Task(Base):
|
||||
__tablename__ = "tasks"
|
||||
id = Column(Integer, primary_key=True)
|
||||
message = Column(String, nullable=False)
|
||||
user = Column(BigInteger, nullable=False)
|
||||
channel = Column(BigInteger, nullable=False)
|
||||
date = Column(Date, nullable=False)
|
||||
creation_date = Column(Date, default=datetime.now())
|
||||
|
||||
def __init__(self, message: str, user: int, channel: int, date: datetime):
|
||||
self.message = message
|
||||
self.user = user
|
||||
self.channel = channel
|
||||
self.date = date
|
|
@ -5,5 +5,5 @@ from sqlalchemy.ext.declarative import declarative_base
|
|||
engine = create_engine(config.get("db"))
|
||||
Session = sessionmaker(bind=engine)
|
||||
Base = declarative_base()
|
||||
#from db.foo import Barr
|
||||
from db.Task import Task
|
||||
Base.metadata.create_all(engine)
|
||||
|
|
Reference in a new issue