[ZODB-Dev] Advice On ZODB

Chris McDonough chrism@zope.com
24 Jan 2003 10:19:12 -0500


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')


        
On Fri, 2003-01-24 at 10:06, John Abel wrote:
> Hi,
> 
> Sorry if this is a dumb question, or the wrong place for this.  I wish 
> to use ZODB as a small DB, initially with one connection, but I hope to 
> expand it with ZEO.  I wish to store several types of records, however, 
> they may have the same "key".  Basically, I do I split up my data, into 
> something like tables?  I've read the docs that come with ZODB, and 
> several of the examples on Zope.org, however, none of them give any 
> indication of how to do what I'm after.  I wish to store something like 
> this:
> 
> [Table1]
> client1 	IP
> client2 	IP
> ...
> client10 	IP
> 
> [Table2]
> client1 	Last Polled
> client2 	Last Polled
> ...
> client10 	Last Polled
> 
> etc.
> 
> Hopefully, I've explained this correctly.
> 
> Thank you for your patience.
> 
> John
> 
> 
> _______________________________________________
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
> 
> ZODB-Dev mailing list  -  ZODB-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zodb-dev
-- 
Chris McDonough <chrism@zope.com>
Zope Corporation