[ZODB-Dev] Advice On ZODB

John Abel john.abel@pa.press.net
Fri, 24 Jan 2003 16:13:57 +0000


Ok, but what if I need to store more data, per root?  I have details on, 
for example, a number of processes, for each IP, that I need to store. 
 Is that were PersistentList() comes into it?  Would I need something 
like this?

class Host(Persistent):
    def __init__(self, ip):
        self.ip = ip
        self.last_polled = None
	self.process = PersistentList()

    def setLastPolled(self, t):
        self.last_polled = t

In which case, how do I update self.process?

Sorry if this is a bit simple, but I really appreciate the help you guys 
are giving.

John

Chris McDonough wrote:

>This may help:
>
>http://www.zope.org/Members/mcdonc/HowTos/gainenlightenment
>
>ZODB is not table-driven like a relational database.  It's an object
>database, so you should try to create objects that represent your
>problem domain and store them in ZODB.  So for instance if the data
>you're trying to store is information about internet hosts, you might
>have a Host class:
>
>import ZODB
>from ZODB.FileStorage import FileStorage
>from ZODB import DB
>from Persistence import Persistent
>
>class Host(Persistent):
>    def __init__(self, ip):
>        self.ip = ip
>        self.last_polled = None
>
>    def setLastPolled(self, t):
>        self.last_polled = t
>
># create a storage
>fs = FileStorage('afile')
>db = DB(fs)
>
>#... get a ZODB connection ...
>conn = db.open()
>
># get the root ZODB namespace
>root = conn.root()
>root['host1'] = Host('192.168.0.1')
>root['host2'] = Host('192.168.0.2')
>
>  
>