Refactor: remove implicit use of db and db.session in model, controllers, etc #503
Closed
23 tasks done
Labels
code-improvement
Make code/structure better
good first issue
Good for newcomers
help wanted
Extra attention is needed
BIG NOTE: This work is in progress in branch
issue_503_db_session_refactoring
This is a general issue to group several independent issues with the code. In summary, there are many places where there is an implicit dependency on the
db.session
which Flask manages, which therefore couples the code to Flask unnecessarily.For example, the various services have
from lute import db
, and then service methods usedb.session.query
. It feels to me that instead the service should be classes instantiated with asession
object, and useself.session
in each method as needed. Then the flask controllers should instantiate the services with thedb.session
, and use them as before.Notes on the work:
I'll add to the list of items below as I come across places to work on.
business repos
Repository
: change the constructor to take a session, and use self.session instead of self.db.sessionRepository
: change the constructor to take a session, and use self.session instead of self.db.sessionORM-level repositories in lute/models/
Many classes have static methods (e.g.
find
etc) that use adb.session
. I'd like to take all of those and move them to Repository classes, e.g,BookTag
will haveBookTagRepository
which will take a session arg in its constructor, and then all static methods can be moved out of BookTag and into the new repo class as instance methods.Change parser settings reads
Convert services to classes (?) or pass session explicitly
Change "service" modules to objects that take a db.session as a parameter, and use that
self.session
everywhere instead ofdb.session
?? Optionally, pass the session as a parameter to each function that needs it.remove db imports where possible
The text was updated successfully, but these errors were encountered: