Deviation from object-relational mapping (pySQLFace)

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Mon Oct 13 10:33:10 CEST 2008

sulyokpeti at a écrit :
> I have made a simple python module to handle SQL databases:
> Its goal to separate relational database stuff (SQL) from algorythmic
> code (python). A SQLFace is a facade initialized with a configuration
> file (XML). It provides callable command objects for each sql query.
> The call substitutes template variables with its parameters, and
> returns the result of the query.
> I would like to get some opinions on this approach.

First, I really don't see the point of XML for something as simple as 
specifying a SQL query and a couple metadata. This would be better done 
directly in Python using a metaclass, inheritance and a couple class 
attributes, ie:

from SQLFace import Query, Statement

class WbsTotal(Query):
    expression="SELECT hours,wbs FROM wbs_total"
    out = ['hours', 'wbs']

class AddProject(Statement):
          INSERT INTO projects (project, description)
          VALUES (%s, %s)
     in_ = ['project', 'description']

Also, I'd rather have Queries being iterators (delegating to the cursor) 
instead of calling cursor.fetchall and returning the whole result.

My 2 cents

NB : btw, did you have a look at SQLAlchemy's low-level 
python-relational integration part (*not* the 'orm' part) ?

More information about the Python-list mailing list