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.

本文标签: