What is the right way to use PostgreSQL with PyQt5

Nenad Lamza <[email protected]> Wed, 10 Jun 2020 23:42:31 +0200
Newsgroups gmane.comp.python.pyqt-pykde
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------7D872262A6F3C395206A77F7
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

Thanks Sibylle, do you know how much work it takes, inventing completely 
new MVC? I haven't found any example of it (SQLAlchemy, psycopg2, 
QTableView, (QDataWidgetMapper) together) on the web. Can you put any 
link. It is much more practical and logical to use PyQt Sql classes with 
QTableView. I avoid QAbstractItemModel and use it only for very very 
special cases. It is so sad that Qt and PyQt haven't documented what 
PostgreSQL drivers and what version of them we should use with 
particular Qt/PyQt versions. And because of that you suggest me to turn 
the upside down the whole Qt MVC framework. I won't do that. The app 
with standard PyQt MVC, QSqlDatabase, QSqlQuery, QSqlQueryModel, 
QSqlQueryModel,..., QTableView works so great that I think it is easier 
to (randomly) find the right combination of drivers than write the whole 
new framework. Nenad Am 10.06.2020 um 14:34 schrieb Nenad Lamza:

> Thanks Barry (and also Dennis) to your answers.
>
> So, I have a choice:
>
> 1. Use standard PyQt MVC, QSqlDatabase, QSqlQuery, QSqlQueryModel,
> QSqlQueryModel, QTableView,..., but without ORM like SqlAlchemy, and
> potentially have problems with PostgreSQL drivers
>
> 2. Use other PostgreSQL drivers like psycopg2 and don't use PyQt MVC and
> Sql classes and use ORM like SqlAlchemy with business logic and objects.
> Isn't the whole point of (Py)Qt MVC to use all those classes I
> mentioned? I can't imagine in that case (without PyQt Sql classes and
> using SqlAlchemy) how would I present data to the user in eg. QTableView
> or some other GUI table on screen? Building my own MVC (it takes years)?
>
You can use the Qt Model-View classes, just without QtSql. Instead you
could create your own Model class, subclassed from QAbstractItemModel or
use a QStandardItemModel (or subclass that). And put your data, got via
SQLAlchemy or directly from psycopg2, into that model. QTableView and
QDataWidgetMapper can use that just as well as the QSql...Model classes.

HTH
Sibylle


--------------7D872262A6F3C395206A77F7
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <pre class="moz-quote-pre" wrap=""><div class="moz-txt-sig">Thanks Sibylle,

do you know how much work it takes, inventing completely new MVC? I haven't found any example of it (SQLAlchemy, psycopg2, QTableView, (QDataWidgetMapper) together) on the web. Can you put any link. It is much more practical and logical to use PyQt Sql classes with QTableView. I avoid QAbstractItemModel and use it only for very very special cases.

It is so sad that Qt and PyQt haven't documented what PostgreSQL drivers and what version of them we should use with particular Qt/PyQt versions.

And because of that you suggest me to turn the upside down the whole Qt MVC framework. I won't do that. The app with standard PyQt MVC, QSqlDatabase, QSqlQuery, QSqlQueryModel, QSqlQueryModel,..., QTableView works so great that I think it is easier to (randomly) find the right combination of drivers than write the whole new framework.

Nenad


Am 10.06.2020 um 14:34 schrieb Nenad Lamza:
</div></pre>
    <blockquote type="cite" style="color: #000000;">
      <pre class="moz-quote-pre" wrap="">Thanks Barry (and also Dennis) to your answers.

So, I have a choice:

1. Use standard PyQt MVC, QSqlDatabase, QSqlQuery, QSqlQueryModel, 
QSqlQueryModel, QTableView,..., but without ORM like SqlAlchemy, and 
potentially have problems with PostgreSQL drivers

2. Use other PostgreSQL drivers like psycopg2 and don't use PyQt MVC and 
Sql classes and use ORM like SqlAlchemy with business logic and objects. 
Isn't the whole point of (Py)Qt MVC to use all those classes I 
mentioned? I can't imagine in that case (without PyQt Sql classes and 
using SqlAlchemy) how would I present data to the user in eg. QTableView 
or some other GUI table on screen? Building my own MVC (it takes years)?

</pre>
    </blockquote>
    <pre class="moz-quote-pre" wrap="">You can use the Qt Model-View classes, just without QtSql. Instead you 
could create your own Model class, subclassed from QAbstractItemModel or 
use a QStandardItemModel (or subclass that). And put your data, got via 
SQLAlchemy or directly from psycopg2, into that model. QTableView and 
QDataWidgetMapper can use that just as well as the QSql...Model classes.

HTH
Sibylle</pre>
  </body>
</html>

--------------7D872262A6F3C395206A77F7--