From bc1bbed07f4fd3e952a8d8d40a11f28e635f5c6c Mon Sep 17 00:00:00 2001 From: flifloo Date: Wed, 27 May 2020 23:19:51 +0200 Subject: [PATCH] Add Task to database --- db/Task.py | 19 +++++++++++++++++++ db/__init__.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 db/Task.py diff --git a/db/Task.py b/db/Task.py new file mode 100644 index 0000000..dae228c --- /dev/null +++ b/db/Task.py @@ -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 diff --git a/db/__init__.py b/db/__init__.py index d414ccb..ca98567 100644 --- a/db/__init__.py +++ b/db/__init__.py @@ -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)