Skip to content. | Skip to navigation

Personal tools
Log in
You are here: Home ZODB is the storage for me?

ZODB is the storage for me?

Still wading through the many options available for Python persistent storage.

Okay, so I stumbled upon the ZODB as a storage medium and it has intrigued me.  I think of it kind of like this:

RDBMS:

RDBMS stands for Relational Database Management System and it is a name for typical relational database.  Any of the number of database that use the Structured Query Language or SQL.  I have a small background in SQL and I understand how it works...for the most part.  It's structured and relational!  It's also comfortable to me, but it has some cons.  For instance, it's just another thing to maintain.  That offers some flexibility of course, but it also increases overhead.  Also, most SQL databases have to be ran as a separate process on the server.  This can lead to more stuff to take care of.  The traditional RDBMS is like a shelf in my daughter's room to store her dolls and stuffed animals.  All the bears go on shelf one, all the garaffs go on shelf two, all the dolls go on shelf three and all the puppet-like creatures go on shelf four.  They are nicely ordered and easily retrieveable.  The SQL would be like me.  For example my daughter could ask me "Dad, can you get me all the bears that are brown from my shelf?"  So, if her bedroom is the SQL database and the toyshelf is a table within the database, her 'query' for me would look something like this in SQL:

SELECT bears
FROM toyshelf
WHERE color = "brown"

So, I would scan the toyshelf with and grab only the brown bears.

OODBMS:

Object-oriented Database Management Systems are a little different.  The one that I have been trying to learn is ZODB which stands for Zope Object Data Base.  Instead of our toyshelf senario above, ZODB handles data differently.  Okay, picture my daughter's room again with her toys, but this time all the stuff is stored in a big toybox.  All the bears, dolls, garaffs, and puppets are all thrown together in the same container.  Okay, so how to we get just the brown bears?  Well that is the intresting part.  We can query the toybox and return only objects with the attributes we specify.

For example:

My daughter could ask a similar question: "Dad, can you get me all my brown bears in my toybox?"

That would look something like this in ZODB (using Zope)

import persistent

class toys(persistent.Persistent):
def __init__(self, name, type, color):
self.name = name
self.type = type
self.color = color

And this is the part that I'm still learning.  You can use the class 'toys' to add data to the toybox db in a way similar to this:

x = toys('Bingo', 'bear', 'brown')  I know, Bingo is gray, but just pretend for the sake of example.

And you could later retrieve all the brown bears like this?????

for i in dbroot['toyshelf']:
if i.type == 'bear' & i.color == 'brown':  
print name

Or something like that.  I'm still struggling with how you retrieve data from the ZODB.  The point is, you retrieve objects from a container and you can filter results based on attributes.  This makes more since to me because I'm more of a tag it and bag it kind of storage guy rather than a neat and tidy shelf kind of guy.

I found a really cool document by "Benji York (http://benjiyork.com)" here: http://benjiyork.com/quick_start/

I'll try to go through that tonight and see if that starts putting all the Zope pieces together for me.

Document Actions
Other Things

/codesamples