main options¶
Any sqlwidget needs a session as well.
Metadata is also used when auto-loading tables referenced by foreign keys to display a better representation of the referenced record.
dbproxy¶
Since a typical scenario is to have to provide a session different in each SqlWidget and a metadata, an object is provided -dbproxy- that can be initialized from the engine specification:
from sqlkit.widgets import SqlMask, SqlTable
from sqlkit import DbProxy
db = DbProxy(engine="sqlite:///model/movies.sqlite")
SqlTable("movies", dbproxy=db)
below you can see some alternatives that would work as well:
Session = sessionmaker(bind=self.metadata.bind, autocommit=False)
sess = Session()
meta = MetaData()
meta.bind = "sqlite:///model/movies.sqlite"
#
SqlTable("movies", session=sess, metadata=meta)
# passing a mapped class (Movie here is build with declarative layer):
# the metadata is found from the mapper.local_table.metadata
SqlTable(Movies, session=sess)
Session are created with autoflush=False, expire_on_commit=False but can be changed when building DbProxy.
Since version 0.8.6 default value for autocommit has been turned to True to prevent idle in transaction in postgresql.