SQLalchemy会话在桌面应用程序中处理
我想在单个用户桌面(PYQT5)应用程序中有关SQLalchemy会话处理的一些建议。
该应用程序是一个音乐播放器,其中轨道数据存储在数据库中。关键是该应用程序具有“下一个轨道”的概念,并且在播放该轨道时需要检索数据(路径,长度,标题等)。用户可以随时更改下一个曲目。
当前,该应用程序使用中的ORM将功能与session()作为session:
上下文管理器中的功能。这意味着,如果应用程序存储“下一个轨道”对象,则该对象以后需要时将其分离。
选项:
在
中包装对象访问如果不在会话中的对象:
和add()
it或get()
(如有必要)。set
expire_on_commit
<代码> false在应用程序启动时启动会话并保持该会话无限地打开
这些替代方案中的任何一个都比其他替代方案更好/更糟?我错过了一种更好的处理方式吗?
I'd like some advice about SQLAlchemy session handling in a single user desktop (PyQt5) application.
The application is a music player where track data is stored in the database. Key is that the application has a concept of "next track" and will need to retrieve data (path, length, title, etc) when that track is played. The next track may be changed at any time by the user.
Currently, the application wraps functions using the ORM in a with Session() as session:
context manager. That means that if the application stores the "next track" object, that object is detached when it is needed later.
Options:
wrap object access in an
if object not in session:
andadd()
it orget()
it if necessary.set
expire_on_commit
toFalse
start a session when the application starts and hold that session open indefinitely
Is any one of those alternatives better/worse that the others? Have I missed a better way of handling this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论