SQLAlchemy: When to initialise a session
Loris Bennett
loris.bennett at fu-berlin.de
Tue Feb 8 08:55:51 EST 2022
Hi,
I am writing a fairly simple command-line application which will just
add or delete an entry in a database and then generate a corresponding
email.
I am using SQLAlchemy to wrap a class around a database and have
class DatebaseWrapper():
"""Encapsulation of the database"""
def __init__(self, url):
self.engine = create_engine(url)
Should I extend the initialisation to
def __init__(self, url):
self.engine = create_engine(url)
self.session = sessionmaker(self.engine)
since each there will be only one session per call of the program?
Or, since I am writing the database wrapper as its own module for
possible reuse, should the program using the wrapper class
initialise the session itself?
Cheers,
Loris
--
This signature is currently under construction.
More information about the Python-list
mailing list