[Zope-dev] Experiments with ORMapping

Shane Hathaway shane@digicool.com
Thu, 10 May 2001 11:32:12 -0400


Kapil (and others),

Although very sketchy and I can't guarantee anything works, my
experiments with object-relational mapping in Zope are found at
http://www.zope.org/Members/hathawsh/ormapping.tar.gz .  If ORMapping.py
is in the ZODB directory, you can use the following custom_zodb.py to
run Zope on top of Postgres using PoPy:

    import ZODB
    from ZODB.ORStorage import ORStorage
    import PoPy
 
    connection = PoPy.connect('user=zodb dbname=zodb')
    storage = ORStorage('pgsql!', connection, PoPy, create=1)
    DB = ZODB.DB(storage)

The initial approach turned out to be rather problematic, since by
default everything is stored in Postgres as a large binary object.  Zope
creates literally thousands of objects when starting for the first time
and a few hundred each time thereafter.  Postgres does not deal well
with large binary objects so start time is something on the order of 10
minutes this way and hard drive space gets eaten up faster than Jim can
code. :-)

But storage of binary pickles was never the intention anyway.  I created
a little interface that would allow you to store different classes in
different PostgreSQL tables.  Before I got to implementing anything,
though, I had to move to another project.  But the file "sketch" shows
(I hope) what I had in mind for making this work: programmers would call
a bunch of functions that would put together a relational mapping tree.

Now, in our discussion yesterday we decided ORStorage wasn't the right
way to achieve relational mapping because there is no way for the
database storage layer to have any context just given an OID.  If we
instead consider writing a replacement for the stuff that's mainly in
Connection.py, life gets a lot simpler.  At this level it *is* possible
to know the parent OID of an object, though the current codebase does
not use this opportunity.  Also, we wouldn't have to pickle and unpickle
unnecessarily.

So, if we have context, the relational mapping tree can work.  It would
turn Zope into a purely relational application server, which a lot of
folks apparently want.  ;-)

Shane