SQLalchemy会话在桌面应用程序中处理

发布于 2025-02-10 13:22:04 字数 544 浏览 1 评论 0原文

我想在单个用户桌面(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: and add() it or get() it if necessary.

  • set expire_on_commit to False

  • 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文