admin管理员组文章数量:1182257
I’m a beginner programmer and have recently learned how to use Flask and SQLAlchemy to work with databases. While working with Flask, I always used scoped_session, which made sense for managing connections in a web application where multiple requests might come in simultaneously.
Now, I’m working on a desktop application and I’m wondering about the best practice for managing database connections. Specifically:
Should I use scoped_session in a desktop app, even though it's not a web app? Alternatively, is it better to open a connection with the engine, perform the database operation, and then close it each time I need to retrieve or modify data? What are the pros and cons of each approach in the context of a desktop application?
I want to make sure my app is efficient and doesn’t end up leaking database connections or unnecessarily complicating the code.
Any insights or advice would be greatly appreciated!
Edit 1: My app is single threaded and for single user to use. It is simple project and my question is just about when to use what. When I was working with Flask I always used scoped session and now I can use it too but should I? That is what I am wondering about.
本文标签:
版权声明:本文标题:python - Should I use scoped_session or openclose connections manually in a desktop app with SQLAlchemy? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738197477a2068232.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论