Move database loading into the db module
This commit is contained in:
parent
eb88f55cef
commit
13e135491c
@ -121,11 +121,7 @@ if __name__ == '__main__':
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
dirname = os.path.dirname(os.path.realpath(__file__))
|
||||
dbpath = os.path.realpath(os.path.join(dirname, '..', '..', 'db', 'data.sqlite'))
|
||||
db = sa.create_engine(f"sqlite:///{dbpath}")
|
||||
|
||||
session = sa.orm.Session(db)
|
||||
session = db.load_db()
|
||||
|
||||
# logging.basicConfig()
|
||||
# logger = logging.getLogger('sqlalchemy.engine')
|
||||
|
@ -2,6 +2,8 @@ import sqlalchemy as sa
|
||||
import sqlalchemy.ext.declarative.base
|
||||
import sqlalchemy.orm
|
||||
|
||||
import os.path
|
||||
|
||||
|
||||
###############################################################################
|
||||
Base = sqlalchemy.ext.declarative.declarative_base()
|
||||
@ -32,3 +34,12 @@ class Task(Base):
|
||||
secondaryjoin=id == depends_association.c.second_id,
|
||||
backref="parents"
|
||||
)
|
||||
|
||||
|
||||
###############################################################################
|
||||
def load_db() -> sa.orm.Session:
|
||||
dirname = os.path.dirname(os.path.realpath(__file__))
|
||||
dbpath = os.path.realpath(os.path.join(dirname, '..', '..', 'db', 'data.sqlite'))
|
||||
db = sa.create_engine(f"sqlite:///{dbpath}")
|
||||
|
||||
return sa.orm.Session(db)
|
||||
|
Loading…
Reference in New Issue
Block a user