[PyQt] Re: PyQt and DB API.

Alberto Berti alberto at metapensiero.it
Mon May 19 02:47:28 BST 2008


>>>>> "Andreas" == Andreas Pakulat <apaku at gmx.de> writes:

    Andreas> On 17.05.08 23:47:49, objectref wrote:
    Andreas> Please don't hijack other people's threads.

    >> As I have the opinion that "standard" is a good thing, do you
    >> think that I better use some other module that is DB-API
    >> compliant or PyQt is best to be used in this case?

    Andreas> Well, that depends on two things:

    Andreas> a) is there something that Qt/PyQt delivers
    Andreas> out-of-the-box, which you'd need to write yourself with
    Andreas> the builtin DB-API? (for example it has support for the
    Andreas> model/view stuff, it ships with a couple of databases
    Andreas> supported, while python only supports sqlite out of the
    Andreas> box)

    Andreas> b) which API is nicer for you to work with? (unasked
    Andreas> answer from me: Qt/PyQt is a _lot_ nicer for me
    Andreas> personally, DB-API feels like the C-API that the
    Andreas> databases offer)


We (me and my collegues) choosed a "third way", and this is to use an
advanced python orm library like SQLAlchemy together with Qt4
model/view/delegate support. This approach decouples object selection,
relations and persistence from display and "through form"
object manipulation. The other advantages are that the "domain logic" can be
reused, for example to build another front-end (e.g. a web
application) or a tool to transfer data to and from the
database. Also, that "layer" can be the location where things like
data validation and other model item's roles values are defined.

The goal is also to sepearate the knowledge (to some level) needed to
model databases and data relations from the knowledge needed to build
a form or a group of forms that represent a certain domanin problem.
So the developer that knows the problem and that has to build a data
driven form has to:

- tag widgets with binding info in designer (using dynamic props or
   just the widget name) and save the form .ui;

- define the python class that will contain signal handlers, custom
  init and so on;

- specify how to assemble these pieces and where the data comes from
  in a configuration file.

All the process is briefly explained here
http://www.pypapi.org/rdg/wiki/Tutorials/Dev/TableAndForm . That
tutorial is written in italian but it should be understandable by the
average programmer by reading the examples.

That library isn't ready yet to be used as a generic framework because
some things needs to be separated and factored out, but that is the
mid term goal if founding keeps coming:)
The code is licensed under GPLv3 so feel free to download is and reuse
in your own project or contribute back:)

cheers,
Alberto



More information about the PyQt mailing list