[Zope3-dev] Queries (was Re: personal conceptual questions)
Jeffrey P Shell
jeffrey@cuemedia.com
Wed, 7 May 2003 17:31:33 -0600
Whee! Happy to pop back in for a moment. I'll try to find time to
follow up on all the relations discussions because I still find myself
caring about that a lot. Queries are the other big thing.
I really like the concept of APE, but found that I couldn't use it with
my existing database application (instead, I'm ending up with something
that's halfway between APE and Modeling, using a lot of Table Gateway
pattern based objects). The main reason that I couldn't go with APE
was that I couldn't find an easy way to pull objects out of a
relational storage (since APE is so transparent) according to a set of
criteria, such as "Get me all Shows between May 5 2003 and June 6
2003". If I had written the application for Zope, I would have had one
or more catalogs that I could query with the catalog query language.
But since it's in an RDBMS, I already have this all set up with SQL.
What would be nice is to be able to have some sort of query language
that could go down closer to the storage level and not the application
level (where catalog is). This would make working with and querying
other storage types easier.
The Modeling framework (an Enterprise Objects Framework inspired O-R
framework for Python) has fetch specifications:
from Modeling.FetchSpecification import FetchSpecification
from Modeling.Qualifier import qualifierWithQualifierFormat
qualifier=qualifierWithQualifierFormat('lastName=="Hugo"')
fetchSpec=FetchSpecification(entityName='Writer',
qualifier=qualifier)
objects=ec.objectsWithFetchSpecification(fetchSpec)
http://modeling.sourceforge.net/UserGuide/ec-simple-fetch.html
It can even do complex queries like:
qual=qualifierWithQualifierFormat('author.pygmalion.lastName
caseInsensitiveLike 'r*')
fetchSpec=FetchSpecification(entityName='Book', qualifier=qual)
objects=ec.objectsWithFetchSpecification(fetchSpec)
Which generates SQL like:
SELECT t0.id, t0.title, t0.FK_WRITER_ID, t0.PRICE
FROM BOOK t0
INNER JOIN ( WRITER t1
INNER JOIN WRITER t2
ON t1.FK_WRITER_ID=t2.ID )
ON t0.FK_WRITER_ID=t1.ID
WHERE t2.LAST_NAME LIKE 'R%'
http://modeling.sourceforge.net/UserGuide/node54.html
This returns book objects, but based on the value of a sub-subobject's
attribute match of the query.
I'd be happy with something like this that could query ZODB, and could
query other storages (via APE or something else) in the same manner.
Not sure if it can happen, but it's another little dream of mine.
Another dream I have no time to do anything about.