[DB-SIG] Re: ZODB

Magnus Lycka magnus@thinkware.se
Fri, 14 Feb 2003 16:36:19 +0100


zohar wrote:
> >From where can I access the prompt or utility to make tables in ZODB 2.6

It's a program you know very well... It's called python.exe...
Perhaps a persistent mapping of tuples will do what you want?

Here's a tiny example:

Session 1:

Python 2.2.1 (#34, Sep 27 2002, 18:37:42) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import ZODB, ZODB.FileStorage
 >>> from ZODB.PersistentMapping import PersistentMapping
 >>> db = ZODB.DB(ZODB.FileStorage.FileStorage('test.fs'))
 >>> people = PersistentMapping()
 >>> db.open().root()['people'] = people
 >>> people['Guido'] = ('van Rossum', 'BDFL')
 >>> people['Tim'] = ('Peters', 'timbot')
 >>> get_transaction().commit()
 >>> ^Z

Session 2:

Python 2.2.1 (#34, Sep 27 2002, 18:37:42) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import ZODB, ZODB.FileStorage
 >>> db = ZODB.DB(ZODB.FileStorage.FileStorage('test.fs'))
 >>> print db.open().root()['people']
{'Tim': ('Peters', 'timbot'), 'Guido': ('van Rossum', 'BDFL')}
 >>>

See? There they are, just where we put them!

ZODB has no concept of tables or query language. It's not like
an RDBMS where you copy the variables from your program to the
database and back again. ZODB is more like having battery
backup for your RAM... Your python variables persist from one
run to the next.

It's not quite like that, but it gives you a picture. With
ZODB you don't have two memory model: The python model and
the SQL model, you have one model: The python model.

ZODB relies on two things:
1. All persistent objects must be directly or indirectly
    reachable from a special root object. This root object
    is like a dict. If an object x is an attribute of another
    object that it an attribute of a third object that is
    placed in this root dict, then x will be persistent.
    Above, we do this in the line
    db.open().root()['people'] = people
2. For the database to be updated when mutable objects are
    changed, they must either inherit a special persistence
    base class, or set an attribute ._p_changed when they
    are modified. Above, we use the PersistentMapping class
    while inherits the persistence base class, and a tuple,
    which isn't mutable.

ZODB handles storage and atomic transactions, and it has
features that SQL databases lack, such as unlimited undo,
but it does not use a schema (there are third party
products to enforce schemas) or a query language.

For more info about ZODB, follow this link:
http://www.thinkware.se/cgi-bin/thinki.cgi/ZopeObjectDataBase



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se