Reasons to use sqlalchemy in Qt

It really is a “pardon of my ignorance” question, so apologize if it does not meet the requirements.

I want to develop a fairly simple database application. It will be desktop and lightweight, so I'm happy that SQLite will be enough. I also decided on Qt and pyside.

Looking through a ton of tutorials, I continue to encounter sqlalchemy and exlixir (and Camelot). I just wonder, what are the advantages of using sqlalchemy (and elixir) compared to basic QSql in Qt? What would I miss if I didn’t use such a thing.

I know that this is fundamental, but before I can advance in my learning process, I just want to understand this in my head.

+4
source share
2 answers

Basically, you have 3 options.

QtSql

QtSql is a separate module in Qt for working with SQL databases.

Pros:

  • Qt integration could be easier

Minuses:

  • Hard to learn
  • Made for C ++, some redundant code required
  • Need to add another Qt module to your project
  • The documentation looks bad.

sqlite3 module

This module in the Python standard library works with SQLite databases.

Pros:

  • Very easy to use
  • The code is pretty short
  • No external dependencies

Minuses:

  • You need to write SQL queries

SQLAlchemy ORM

SQLAlchemy makes working with databases similar to working with regular classes.

Pros:

  • Object Relational Mapper: provides an object-oriented interface and makes SQL queries for you
  • As soon as you set up the table, working with databases will be pure joy.

Minuses:

  • Steep learning curve

Here is my conclusion:
If you are comfortable writing SQL queries and do not need to work much with databases, use sqlite3. And if you don't mind spending some time learning something amazing, go for SQLAlchemy.

Other projects you mentioned:
Elixir seems dead, and SQLAlchemy now has built-in functionality, perhaps better.
Camelot is just weird ... I would not use it.

+7
source

I'm in a similar situation ... pretty early in the PyQt learning curve, looking for work on some database related projects. I came across what sounds like the same streams that you have ... they talk about sqlalchemy, elixir or Project Camelot in combination with PyQt4. However, none of them seem to delve into the details of specific benefits. Apparently, he suggested that the benefits are obvious to the reader;) For the most part ... I put together the fact that as soon as you reach a certain level of complexity of your project, you will most likely have more or less written some of the main abstractions to process the database using applicable Qt4 objects anyway and that you will be money / time, just to use sqlalchemy / elixir and not "collapse your own". Camelot does this a little more, from what I can say (like the green horn itself).

Here is what I decided in the near future: I plan to break through the first few basic projects using the DB material provided by PyQt. After I like it, I can go back and redo things using sqlalchemy, elixir, etc.

+1
source

Source: https://habr.com/ru/post/1413435/


All Articles