diff --git a/src/pyelephant.py b/src/pyelephant.py index d46f93f..1886099 100755 --- a/src/pyelephant.py +++ b/src/pyelephant.py @@ -1,13 +1,22 @@ #!/usr/bin/env python3 import sqlalchemy as sa -import sqlalchemy.ext.automap +import sqlalchemy.ext.declarative.base import dateparser ############################################################################### -Base = sa.ext.automap.automap_base() -Task = None +Base = sqlalchemy.ext.declarative.declarative_base() + + +class Task(Base): + __tablename__ = "tasks" + + id = sa.Column(sa.Integer, primary_key=True) + title = sa.Column(sa.String, nullable=False) + created_at = sa.Column(sa.DateTime, server_default=sa.func.current_timestamp(), nullable=False) + due_at = sa.Column(sa.DateTime, nullable=True) + active = sa.Column(sa.Boolean, server_default=sa.sql.expression.true(), nullable=False) ############################################################################### @@ -107,11 +116,6 @@ if __name__ == '__main__': dbpath = os.path.realpath(os.path.join(dirname, '..', 'db', 'data.sqlite')) db = sa.create_engine(f"sqlite:///{dbpath}") - Base.prepare(db, reflect=True) - - global Task - Task = Base.classes.tasks - session = sa.orm.Session(db) args = vars(args) func = args['func']