[Zope3-dev] Queries (was Re: personal conceptual questions)
Shane Hathaway
shane@zope.com
Thu, 08 May 2003 10:07:18 -0400
Jeffrey P Shell wrote:
> 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.
Here's one approach you might take with Ape. Write a SQL query that
returns primary keys, then fetch objects by key through an Ape
connection. It might look something like this:
cursor.execute("select key from shows where "
"date >= '2003-05-05' and date <= '2003-06-06'")
rows = cursor.fetchall()
objs = [jar.loadStub((row[0],)) for row in rows]
There are good things about this (caching, for instance) and bad things
about this (caching, for instance.) :-)
> 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.
I've been discussing relationships for exactly this purpose. I want
relationship (and relational) capabilities in ZODB so that I can mimic
them in Ape. I'd like to hide all SQL from the application. But I just
read an article by Fowler that convinced me that hiding SQL is not
always the best thing to do. So now I'm considering a direct-query
interface again. (I wonder if I got the URL from you? ;-) )
http://www.martinfowler.com/articles/dblogic.html
> 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.
+1 ;-)
Thanks for the information about Modeling, though. I still wonder if
mixing Modeling and Ape might work.
Shane