[Zope] Help with Zope2 persistence?

Joe Grace occam@serv.net
Fri, 23 Jul 1999 00:22:28 -0700


Hi,

I'm wondering if it's possible to use Zope persistence outside of Zope
for testing.  I copied the code from the Persistence section of

    http://www.zope.org/Documentation/Reference/ObjectPublishingIntro

I also tried a variety of variations on BoboPOS.Persistent according to
a comment recently made by Michel:

    Actually, Persistence.Persistent.  BoboPOS will work but it's not
'the
    way'.  It's legacy.

So, I've gotten it to "from Persistence import Persistent" and to
inherit, but I don't know what the correct invocation is to create the
database.  BoboPOS.PickleDictionary(), and Persistent.PickleDictionary()
don't work.  I've been perusing code for an example of something which
seems to create a DB from scratch, but the only one I found

I know this is a newbie question, but if someone has a complete sample
code analogous to the following, I'd be very thankful for the insight.
Ideally, it would work outside Zope (getting all the imports correct, if
possible), but just working within Zope would be nice too.

The "has_key" method seems to be a missing link too.  That method
doesn't seem to exist in the objects I was guessing were my DB objects.
I'd like to know how to do that test using Zope2 code.

(I hope this question makes sense.)  Just looking for the basics.

Thanks,

= Joe =

-=-  Basic code fragment from docs follows:  -=-

       #  I'm assuming this changes to "import Persistent from
Persistence" or somesuch?
       import BoboPOS

       #  I'm assuming this changes to "class Person( Persistent):".
       class Person(BoboPOS.Persistent):
               "A persistent person"
               def __init__(self,name,age):
                       self.name=name
                       self.age=age

       # ???  What goes here?
      object_store=BoboPOS.PickleDictionary("people_store.db")

       # ???  Does object_store still use has_key to check for
existence, or is there another method?
      if object_store.has_key("billy"):
               billy=object_store["billy"]
       else:
               billy=object_store["billy"]=Person("Billy",77)
               get_transaction().commit()

       print billy.name, billy.age