Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reasons for using sqlalchemy in Qt

This is really a "pardon my ignorance" question so apologies if it doesn't meet the requirements.

I want to develop a fairly simple database application. It will be desktop based and lightweight so I'm happy that SQLite will suffice. I have also decided upon Qt and pyside.

Looking through the mass of tutorials out there, I keep coming across sqlalchemy and exlixir (and Camelot). I am basically just wondering what advantages there are to using sqlalchemy (and elixir) over basic QSql in Qt? What would I be missing if I didn't use such a thing.

I know this is basic but before I can progress on my self-tuition process, I just want to get this clear in my head.

like image 717
Steven Lee Avatar asked Feb 21 '23 10:02

Steven Lee


2 Answers

Basically, you have 3 options here.

QtSql

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

Pros:

  • Integration with Qt may be easier

Cons:

  • Hard to learn
  • Was made for C++, requires some redundant code
  • Requires adding one more Qt module to your project
  • Documentation looks bad

sqlite3 module

This a module in Python standard library to work with SQLite databases.

Pros:

  • Very easy to use
  • Code is quite concise
  • No external dependencies

Cons:

  • You do have to write SQL queries

SQLAlchemy ORM

SQLAlchemy makes work with databases similar to work with usual classes.

Pros:

  • Object Relational Mapper: exposes an object-oriented interface and makes SQL queries for you
  • Once you've set up the table information, work with databases is pure joy

Cons:

  • Steep learning curve

Here's my conclusion:
If you are comfortable with writing SQL queries and don't have to do a lot of work with databases, use sqlite3. And if you don't mind spending some time to learn something awesome, go for SQLAlchemy.

About the other projects you've mentioned:
Elixir seems dead, and SQLAlchemy has its functionality built-in now, probably better.
Camelot is just weird... I wouldn't use it.

like image 96
Oleh Prypin Avatar answered Mar 02 '23 23:03

Oleh Prypin


I'm in a similar situation... fairly early in the PyQt learning curve, looking to work on some database-related projects. I've ran across some of what sound like the same threads that you have... they talk about sqlalchemy, elixir, or Project Camelot in conjunction with PyQt4. None of them really seem to go into much detail as far as explicit benefits, though. Apparently its assumed that the benefits are inherently obvious to the reader ;) For the most part... what I've gathered is that once you get to a certain level of complexity regarding your project, you'll most likely have more or less written some of the basic abstractions for database handling using the applicable Qt4 objects anyways and that you'd be money/time ahead to just use sqlalchemy/elixir rather than 'roll your own'. Camelot takes that a bit further yet, from what I can tell (as a green horn myself).

Here's what I've decided, for the near future: I plan to work my way thru the first few basic projects, using the DB stuff provided by PyQt. After I'm comfortable with that, then I may go back and rework things using sqlalchemy, elixir, etc.

like image 29
memilanuk Avatar answered Mar 03 '23 00:03

memilanuk