Use declarative bases for the data models
Automapping proved difficult to wrangle many-many relationship naming and wasn't particularly ergonomic. We may as well just use manual ORM specifications...
This commit is contained in:
parent
06742bb382
commit
d714399389
@ -1,13 +1,22 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
import sqlalchemy.ext.automap
|
import sqlalchemy.ext.declarative.base
|
||||||
|
|
||||||
import dateparser
|
import dateparser
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
Base = sa.ext.automap.automap_base()
|
Base = sqlalchemy.ext.declarative.declarative_base()
|
||||||
Task = None
|
|
||||||
|
|
||||||
|
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'))
|
dbpath = os.path.realpath(os.path.join(dirname, '..', 'db', 'data.sqlite'))
|
||||||
db = sa.create_engine(f"sqlite:///{dbpath}")
|
db = sa.create_engine(f"sqlite:///{dbpath}")
|
||||||
|
|
||||||
Base.prepare(db, reflect=True)
|
|
||||||
|
|
||||||
global Task
|
|
||||||
Task = Base.classes.tasks
|
|
||||||
|
|
||||||
session = sa.orm.Session(db)
|
session = sa.orm.Session(db)
|
||||||
args = vars(args)
|
args = vars(args)
|
||||||
func = args['func']
|
func = args['func']
|
||||||
|
Loading…
Reference in New Issue
Block a user